I have a restful webservice for which iam writing a new method call. The purpose of the new method call is to revoke the status of a person to “NO”.
All that I have to send in the request is a Person_Id for which the status needs to be changed to “NO”.
Should I be using PUT or POST to do this?
If I use put, can I just send the person_id as a path parameter and not use any xml at all.
(like : http://serverName/PersonServices/Person/123456) and in the service layer, i have my code like this.
@PUT
@Path("/Person/{person_Id}")
@Consumes("application/xml")
@Produces("application/xml")
public JAXBElement<GetUsageTokenType> updateLicenseStatus(
@PathParam("person_Id") final Long personId) {
//code to change the status
}
Or should I be using POST to do this…
Am I right in saying that if I use POST, I need to send xml format?
If you look at Which HTTP methods match up to which CRUD methods? there shows the mapping
If you read the HTTP RFC for each verb’s definition you can see why…
In response to:
then ideally your URL
should probably be
This will help for maintainability if you don’t want to pass any XML/JSON/etc but whether human-readable URLs are a feature of RESTful services is a llloooonnnggg-running argument
As alluded to in the comments RESTful APIs should focus on content and not actions. See: Why does including an action verb in the URI in a REST implementation violate the protocol? for example.
So you’d pass a person to a URL and based on the HTTP verb the relevant CRUD action is taken. If you want to pass just an ID then you’re going to have to guess what update to take when you PUT to the ID… unless you know that there’s never going to be any other update ever ever ever.