HTTP POST with URL parameters - what should the server reply with?
I'm working on designing a RESTFul service which provides CRUD operations for various domain objects. One such object is Person.
We have the following services:
GET /person/list?type=Infant
responds with all persons of the type Infant.
POST /person/list
accepts a list of persons in the payload and creates those records.
Question: Does it make sense for
POST /person/list?type=Infant
in which case, we 开发者_开发百科would create the persons passed in the payload and then respond with a list of all persons of the type Infant?
What's the best practice?
I am not comfortable with this statement: "create the persons passed in the payload and then respond with a list of all persons of the type Infant". The two operations should be performed separately.
I don't think that it makes much sense for /person/list to be the api for adding a person. If anything it should be /person/add. There's nothing specific about REST that forbids you from trying to be clever, but the response I would expect on a /person/add would be the result of the add. Trying to graft on some extra functionality just makes it more complicated for your clients (ie. the people who will be using your API).
精彩评论