简体   繁体   English

服务器命令请求的 HTTP 响应正文

[英]HTTP response body for server command request

I am solving one question with my team about REST API specification.我正在与我的团队解决一个关于 REST API 规范的问题。 We have a case where in some requests we are sending only some particular command via HTTP request for example: We are using POST (now considering PATCH request) to endpoint: /server/startSomeOperation .我们有一种情况,在某些请求中,我们仅通过 HTTP 请求发送一些特定命令,例如:我们正在使用 POST(现在考虑 PATCH 请求)到端点: /server/startSomeOperation Backend developers told us that this request is only telling hardware to start some functionality on backend that affects the measurement of the user but it really has nothing to return.后端开发人员告诉我们,这个请求只是告诉硬件在后端启动一些影响用户测量的功能,但实际上没有什么可以返回的。 My question is: Should we (according to some REST API specification) always return body of such a request when we know that no additional returned data will be needed except HTTP status code?我的问题是:我们是否应该(根据一些 REST API 规范)在我们知道除了 HTTP 状态代码之外不需要其他返回数据时总是返回此类请求的正文? Until now we were strictly following the rule that every request needs to have some sort of body returned but until now every body response even when it was a command to a server made sense.到目前为止,我们严格遵循每个请求都需要返回某种类型的主体的规则,但直到现在,即使是对服务器的命令,每个主体响应都是有意义的。

Should we (according to some REST API specification) always return body of such a request when we know that no additional returned data will be needed except HTTP status code?我们是否应该(根据某些 REST API 规范)在我们知道除了 HTTP 状态码之外不需要其他返回数据时总是返回此类请求的主体?

No - it is perfectly fine to send a 204 No Content or a 205 Reset Content when the semantics of your response is well aligned with the standard meaning of those codes.否 - 当您的响应的语义与这些代码的标准含义完全一致时,发送204 No Content205 Reset Content是完全可以的。

You also have the option of declaring that the "representation of the status of, or results obtained from, the action" is zero bytes long, in which case you could use a 200 OK with a Content-Length header.您还可以选择声明“操作的状态或结果的表示”长度为零字节,在这种情况下,您可以使用200 OK内容长度header。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM