Hi Im working on a REST API for a e-commerce app and had a couple questions about which are the correct URNs to map some specific actions, having in mind the definition of URI stated on RFC 3986: A Uniform Resource Identifier (URI) is a compact sequence of characters that identifies an abstract or physical resource.
The key takeaway from the dissertation that introduced REST is:
Any information that can be named can be a resource...
Have a look at Resources and Resource Identifiers for more information.
In other words, an action is a resource. In your own words, a URI is a sequence of characters that identifies an " abstract or physical resource". Just because an action doesn't easily map to a tangible object doesn't make it less of a resource.
There are status codes which only exist to respond to 'actions' (eg 202 Accepted
).
All in all, POST /api/posts/{id}/share
seems completely reasonable.
POST
is really there as a 'catch all' for actions. In RFC2616 it says the "function performed by the POST method is determined by the server" and the function performed "might not result in a resource that can be identified by a URI".
The main points:
POST
POST
request.200
, 201
, 202
, 204
, 4xx
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.