问题描述
我已经构建了一个 RESTFul 服务器 API.它的某些部分不控制资源,我无法将相关的 URL + HTTP 方法映射到在服务器上执行的操作.
I have a RESTFul server API which I've built. Some parts of it is not controlling resources and I'm having trouble mapping the relevant URL + HTTP-method to the actions that are executed on the server.
例如我可以使用 POST/backup
备份服务器上的每个资源,但我不确定这是否是最合适的映射.单个资源呢?我应该使用:POST/backup/id
或通过将 id 声明为我发送的变量来指定它:POST/backup
e.g. I can backup every resource on the server with POST /backup
, but I'm not sure if this the most appropriate mapping. What about a single resource? Should I specify it with: POST /backup/id
or by declaring the id as a variable that I send: POST /backup <id>
请给我一些关于如何最恰当地构建它的提示,以便我的 API 易于掌握.
Please give me some tips on how to structure this most appropriately so that my API is easy to grasp.
推荐答案
这取决于每次调用时是否在数据库上创建一个新的备份对象,或者您是否有很多备份对象(即不同文件的备份,对于示例)只保存最后一个值.
This depends if you create a new backup object on database each time you call, or if you have many backup objects (that is, backups for different files, for example) that hold only the last value.
POST/backups
用于创建一个新对象,因此如果您总是创建一个新备份,那么正确答案是.
POST /backups
is used to create a new object, and so the correct answer if you always create a new backup.
PUT/backups/id
如果您要更新同一对象中的备份数据.
PUT /backups/id
if you are updating your backup data in the same object.
这篇关于在服务器上执行操作的 RESTful HTTP 请求是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!