1

I am implementing a REST api for setting and retrieving a resource.

I have been asked to implement a strange PUT, whereby a JSON object is stored, while another JSON object is returned.

PUT /object/{id} - stores the object with a specified identifier, and returns properties about that object in a different object

The upstream team is requesting this purely for convenience - one action (the storage of the object) is always followed by a request of derived information (based on the contents of the object).

In my mind, in a RESTful api, these would be two calls: one to store the object, then another to retrieve some data about that object id.

PUT /object/{id} - stores the object with a specified identifier
GET /object/{id} - retrieves the object with a specified identifier
GET /object/{id}/properties - retrieves properties about the object

One thought I had was to expand the object itself to include space for the "derived properties", so that the PUT sends in an object that is essentially incomplete, and then the returned object is returned with the completed properties data. I have seen many apis branded as RESTful that return a copy of the actual object stored, so this is the basis for this approach, but I have not seen an api that appended additional data.

What is the RESTful approach to obtain this derived data?

Matt Thompson
  • 773
  • 1
  • 10
  • 26
  • [Here's a similar question about post](http://stackoverflow.com/questions/1829875/is-it-ok-by-rest-to-return-content-after-post). I don't think it's a problem as long as you identify the result of the request with a header. Yes you should return the data on a get request, but maybe it's not a big deal if you return it after a successful put as well? *Edit:* if you do decide to return the data after successful put, make sure you call the GET method's function to retrieve the data to avoid duplicating your resources – scrowler Aug 07 '14 at 03:51
  • possible duplicate of [Should a RESTful 'PUT' operation return something](http://stackoverflow.com/questions/797834/should-a-restful-put-operation-return-something) –  Aug 07 '14 at 06:45

0 Answers0