所以我正在尝试使用一个安静的API为我的办公室开发音乐播放器。简而言之,API将能够从youtube下载音乐并将其加载到正在运行的MPD实例的当前播放列表中。我还希望能够使用API
控制播放/音量到目前为止,这是我的想法:
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)
所以这基本上就是我现在的想法。我知道这是非常高的水平,我只想得到一些输入,看看我是否在正确的轨道上。这看起来像是实现这种API的可接受方式吗?
答案 0 :(得分:2)
DELETE清除队列并不酷。改为使用空队列表示。当您希望能够重新排列队列中的项目,逐个删除它们等时,这也会派上用场。您可以获取当前队列,应用更改并将其恢复。
明显更好地将卷建模为具有GET和PUT的单独/status/volume
资源。如果您绝对需要明确的“音量增大”和“音量减小”操作(也就是说,如果您的客户不会跟踪当前音量),也许可以使用PATCH。
同样播放/暂停/停止状态:GET / PUT /status/playback
。
要使用当前状态为客户端播种,请GET /status
回复所发生情况的摘要:当前曲目,音量,播放/暂停。
答案 1 :(得分:1)
我会使用以下两个主要模块:
playlist/{trackId}
source
index
player
playing
track
time
volume
播放列表:
POST playlist {source: ...}
DELETE playlist/{id}
PUT playlist/{id}/index 123
GET playlist
播放器:
PUT player/track {id: 123}
PUT player/time 0
PUT player/playing false
PUT player/playing true
PUT player/volume .95
GET player
你应该使用正确的RDF词汇来表示链接关系和描述你的数据。您可以找到它here。