此 REST API 的参数值应位于何处?为什么?
我有以下 REST API:
POST /users/martin/notify/...
该 API 应该通知用户列表,用户 Martin 有话要说。要通知的用户列表可以从 1 到 1000 不等。一千个用户的列表应该在哪里:查询字符串、HTTP 标头或请求正文?为什么?
I have the following REST API:
POST /users/martin/notify/...
The API is suppose to notify a list of users that the user Martin has something to say. The list of users to be notified can vary from 1 to a thousand. Where the list of a thousand users should be: Querystring, HTTP Header or the Request body? Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请求正文。在实践中,标头和查询字符串通常具有大小限制,您肯定会遇到一千个标识符。从更理论的角度来看,请求正文应该是您希望服务器通过 POST 处理的实体。标头用于有关该实体的协议级元数据;也就是说,帮助实体被处理的信息,而不是实体本身。查询字符串是资源标识符的一部分,但并不是该资源的表示。
Request body. Headers and querystrings often have size limitations in practice that you would definitely hit with a thousand identifiers. At a more theoretical level, the request body should be the entity which you wish the server to process via POST. Headers are for protocol-level metadata about that entity; that is, information that helps the entity be processed, but not the entity itself. Querystrings are part of the identifier for the resource, and also not a representation of that resource.