2

I've got an XML document which may hold one or more entities. For the sake of this example, let's say those entities are cars.

Now, I'm about to create a REST service which accepts the XML file and carries out create, update and delete operations. I thought I'd simply do :

HTTP POST to /service/car : create cars listed in the in XML document

HTTP PUT to /service/car : update cars listed in the in XML document

HTTP DELETE to /service/var : delete cars listed in the in XML document

However, it is my impression that PUT and DELETE should act on resources (URL's) which represents a specific entity. That is, I could invoke a HTTP DELETE against /service/car/10 to delete car number 10. However, the HTTP/1.1 specification states that

The PUT method requests that the enclosed entity be stored under the supplied Request-URI

This means that I can't simply use a PUT to flag an update operation, I should also add the car id to the URL. However, I've got multiple cars which needs to be batch updated.

I'm tempted to do :

HTTP POST to /service/car/create

HTTP POST to /service/car/update

HTTP POST to /service/car/delete

However, something tells me that this isn't quite how you do things with REST.

Are there any "best practise" on this?

sbrattla
  • 5,274
  • 3
  • 39
  • 63

1 Answers1

0

I would think about the XML document as a "command" resource you're "RESTing" and not the cars. The semantic of the resource type would be "cars-modification-command". I would define an URI /modifications/cars. The HTTP answer would be a list of URIs which could be queried for the result of the command, e.g. the URI for the new cars.

It's a similar question as "how to do I do complex queries in REST-style"? My answer would be: make the query (or in this case: the modification command) a full fledged object of your domain.

Community
  • 1
  • 1
xwoker
  • 3,105
  • 1
  • 30
  • 42