How should I format my REST API when dealing with different types of GET
Let say I have and Order resource. In order to get the resource I want I would do something like this:
GET /orders/{someId}
The question is what do I do when there are different kinds of gets. For example a GET to edit the order or a GET to review the order. Normally you would just use the orders/{someId}
for both, but in this case I need to do some different business logic for each (some auditing).
Perhaps I could do something like this:
GET /orders/{someId}?type=review
But that seems wrong. Thoughts?
GET /orders/{someId}/action
For your needs
GET /orders/{someId}/edit
GET /orders/{someId}/review
GET should not modify the item, so I assume this URLs are just for load the resource, not for modify it.... plz clarify this
You can use different HTTP methods (as a verb), depending on the action that is taking place. This will allow you to keep the path clean and simple.
Examples:
GET /orders/{someId}
PUT /orders/{someId}
POST /orders/{someId}
DELETE /orders/{someId}
GET is used to retrieve, PUT to update, POST to create, and DELETE to remove the resource. This follows basic CRUD (create, read, update, delete). If you need to add any additional filters/parameters, use query parameters.
链接地址: http://www.djcxy.com/p/71268.html上一篇: HTTP基本认证,而不是TLS客户端认证