What is the easiest way to implement this proposed API?
So I am trying to create a music player for my office with the rest of the API. In short, the API will be able to download music from youtube and load it into the current playlist of a running MPD instance. I also want to be able to control playback / volume using the API
Here's what I thought so far:
Endpoint: /queue
Methods:
GET: Gets the current MPD playlist
POST: Accepts JSON with these arguments:
source-type: specify the type of the source of the music (usually youtube, but i might want to expand later to support pulling from soundcloud, etc)
source-desc: Used in conjunction with source-type, ie, if source-type were youtube, this would be a youtube search query
It would use these arguments to go out and find the song you want and put it in the queue
DELETE: Would clear the queue
Endpoint: /playbackcontrol
Methods:
GET: Returns volume, whether playing, paused, or stopped, etc
POST: Accepts JSON with these arguments:
operation: describe the operation you want (ie, next, previous, volume adjust)
optional_value: value for operations that need a value (like volume)
So basically what I'm thinking about right now. I know this is a really high level, I just wanted some input to see if I am on the right track right. Does this seem like an acceptable way to implement such an API?
source to share
DELETE to clear the queue is not cool. Print an empty view of the queue instead. This will also come in handy later when you want to reorder the items in the queue, remove them one at a time, etc. - you can GET the current queue, apply changes and DISABLE it.
Volume is clearly better modeled as a separate resource /status/volume
with GET and PUT. Maybe PATCH if you absolutely need different volume up and volume down operations (that is, if your client won't be tracking the current volume).
The same for the play / pause / stop state: GET / PUT /status/playback
.
To seed the client with the current status, make a GET /status
reply to the summary of what is happening: current track, volume, play / pause.
source to share
I would use the following 2 main modules:
playlist/{trackId}
source
index
player
playing
track
time
volume
Playlist:
- adding track:
POST playlist {source: ...}
- deleting a track:
DELETE playlist/{id}
- track order:
PUT playlist/{id}/index 123
- get a list of tracks:
GET playlist
Player:
- Loading a track:
PUT player/track {id: 123}
- rewind track:
PUT player/time 0
- stop the player:
PUT player/playing false
- start the player:
PUT player/playing true
- adjust the volume:
PUT player/volume .95
- Get current status:
GET player
Ofc you must use the correct RDF vocabode for the link relationships and for describing your data. You can probably find it here .
source to share