segler-alex / radiobrowser-api

radio browser server api
GNU Affero General Public License v3.0
73 stars 15 forks source link

Implement all methods in API v2 #8

Closed TheLastProject closed 8 years ago

TheLastProject commented 8 years ago

Currently, most methods only seem available in API v1, yet the Playable station url is on v2. While I'm unsure why this was done in the first place (as the v1 API has nothing listening on that URL it seems), this situation forces developers to use two versions of the API. It would simplify third-party code if all v1 methods would also be available at v2 or, in this case, if the Playable station url call would be available from API v1.

segler-alex commented 8 years ago

Hi, there is no real api v2 it is just a way for me, to tell people do not use v1 of this specific api-call anymore. the api is evolutionary, i do not design it as a whole. i just add stuff :) and sometimes i also want to change single api calls, because i found out their design was broken somehow, or they are not able to give new features to the users. so i deprecate them which means, i replace their documentation with a newer call that has v2 in it or later maybe v3,.... i do this to not break anything out there. i keep the old version online. i hope i could clarify my style for you. :) greetings from vienna

TheLastProject commented 8 years ago

While I understand that, versioning is generally done API-wide instead of specific to an API call. The reason for this is the ability to use a single base URL and make it easy to know what version you're supporting.

As I'm currently writing a small application that uses the RadioBrowser API (you may have seen a Pext-related user agent), I'm obviously trying to use some API consumption best practices such as setting a base URL in a variable.

In a normal situation, I would just be able to say something like this:

self.baseUrl = "http://www.radio-browser.info/webservice/v2/json/"

def requestData(path):
    return json.loads(urlopen(self.baseUrl + path).read().decode("utf-8"))

However, with the way you have it set up, I need to store 2 different base URLs and make my request function able to switch on version like such:

self.baseUrlv1 = "http://www.radio-browser.info/webservice/json/"
self.baseUrlv2 = "http://www.radio-browser.info/webservice/v2/json/"

def requestData(path, version):
    if version == 1:
        baseUrl = self.baseUrlv1
    else:
        baseUrl = self.baseUrlv2

    return json.loads(urlopen(baseUrl + path).read().decode("utf-8"))

While this does not seem like much complexity, it is unnecessary complexity caused by the way you deal with the versioning and will only get worse as your API evolves.

If all the other functions were also available under http://www.radio-browser.info/webservice/v2/json, I could simply always use API version 2 and not worry per call about which API version I should be using. It also makes it easier for you to tell how many applications are still on v1, because right now you can only see which ones aren't using the new v2 function.

If you feel that you really prefer your way, I'll still use the API, but I simply feel this is an improvement so I wanted to state it :) Thanks for RadioBrowser, by the way!

segler-alex commented 8 years ago

i will not change the api now, it would produce to much double code. and i have even plans to move from php to node.js for the api when i have more time. so for the time beeing i will only make small changes. thank you for using the api and helping keep the ecosystem growing, if you need a feature or a fix, please feel free to contact me. i even thought of moving the api to http://api.radio-browser.info but this is not really a good idea, because, i would have all the endpoints double. maybe some time in the future.

just use the following for the time beeing: self.baseUrlv1 = "http://www.radio-browser.info/webservice/"

TheLastProject commented 8 years ago

Understood, I'll close this issue then as the decision basically seems to be made.

For what it's worth, because http://www.radio-browser.info/gui/#/ asks to drop you a note about apps using it, here is my radiobrowser using project: https://github.com/Pext/pext_module_radiobrowser. Feel free to list it if you want to :)

segler-alex commented 8 years ago

i will add it to the list :) thx!