控制器方法应该 return 有什么最佳实践吗?
Are there any best practices what Controller methods should return?
例如,控制器 return 是否应该在更新后更新实体?
为了符合您的问题,我们可以在动词范围内设置“最佳实践”。 return 每个动词的最佳选项是什么?
我将使用 RESTful Web Services 这本书(第 4 章)来回答您的问题。
这是书中的原文,下面none个字是我的
GET
The server sends back a representation in the response entity-body.
POST
Response of POST request usually has an HTTP status code of 201 ("Created"). Its Location
header contains the URI of the newly created resource.
PUT
The entity-body contains the client's proposed new representation of the resource. What data this is, and what format it's in, depends on the service.
删除
The response entity-body may contain a status message or nothing at all
头部
Retrieve a metadata-only representation.
A client can use HEAD to check wheter a resource exists, or find out other information about the resource, without fetching its entire representation. HEAD gives you exactly what a GET request would give you, but without the entity-body
选项
Contains the HTTP Allow
header, which lays out the subset of the uniform interface this resource supports.
例如,控制器 return 是否应该在更新后更新实体?
为了符合您的问题,我们可以在动词范围内设置“最佳实践”。 return 每个动词的最佳选项是什么?
我将使用 RESTful Web Services 这本书(第 4 章)来回答您的问题。
这是书中的原文,下面none个字是我的
GET
The server sends back a representation in the response entity-body.
POST
Response of POST request usually has an HTTP status code of 201 ("Created"). Its
Location
header contains the URI of the newly created resource.
PUT
The entity-body contains the client's proposed new representation of the resource. What data this is, and what format it's in, depends on the service.
删除
The response entity-body may contain a status message or nothing at all
头部
Retrieve a metadata-only representation.
A client can use HEAD to check wheter a resource exists, or find out other information about the resource, without fetching its entire representation. HEAD gives you exactly what a GET request would give you, but without the entity-body
选项
Contains the HTTP
Allow
header, which lays out the subset of the uniform interface this resource supports.