I’ve decided that I’m going to write an API for my music site. Something that I really want is to implement REST when creating my API. If I wanted the functionality to say, play the next song via the API, how would I go about doing this?
As far as my constructed URL would go, would it be something like API/{ID}/NextSong, API/{ID}/?NextSong, or API/{ID}?NextSong. Or would it be something a bit different than that?
As far as the code side goes, I plan on have the web service running in PHP. I would need some sort of authentication step. What would be the best way to authenticate a user with the API? (I’d imagine that there is probably a really good online resource or something for this.)
Finally, the music player is in HTML5 and Javascript/jQuery. What’s the best way to get the player to actually go to the next song using the web service? I have a nextSong() javascript function, but I’m not sure how to access it. The only thing I can think of is some sort of polling, be it AJAX long-polling, or just timed polling. Is there any other better, more efficient way of doing this?
Thanks for any help, all I really need is a push in the right direction, a lot of what I know so far is due to my experience with Microsoft’s listdata.svc RESTful webservice in Sharepoint 2010. The rest of my knowledge is restricted to this article about REST APIs in PHP.
If you have an URL with “NextSong” in it that would mean you would have to have every users state saved on the server. If I would have a player and work with AJAX against a REST-API I would let the server just be “stupid servant” that does everything I tell it to do and let the logic be on the client side.
For example I would have a service for getting a playlist in JSON or XML format. Parse this on the client. When you listen to a song in that playlist you know where in the playlist you are and when the users or player asks for the next song the musicplayer will look in the playlist (saved in array of objects maybe a linked list where you have properties for previous song and next song?), call the service for start playing song id #####. For example API/{ID}/Play/{SongID} or API/{ID}/Song/{SongID}.
Regards
(EDIT Fixed Typo)