gpt4 book ai didi

rest - 什么是实现这个提议的 API 的 Restful 方式?

转载 作者:行者123 更新时间:2023-12-01 23:52:34 26 4
gpt4 key购买 nike

所以我正在尝试使用 restful 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 的可接受方式吗?

最佳答案

DELETE 来清除队列并不酷。 PUT 一个空的队列表示。稍后当您希望能够重新排列队列中的项目、一个一个地删除它们等时,这也会派上用场——您可以获取当前队列、应用更改并将其放回原处。

Volume 显然更好地建模为具有 GET 和 PUT 的单独 /status/volume 资源。如果您绝对需要不同的“提高音量”和“降低音量”操作(也就是说,如果您的客户不会跟踪当前音量),则可以使用 PATCH。

播放/暂停/停止状态同上:GET/PUT /status/playback

要为客户端播种当前状态,请使用 GET/status 响应并总结正在发生的事情:当前轨道、音量、播放/暂停。

关于rest - 什么是实现这个提议的 API 的 Restful 方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25775798/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com