Forum Stats

  • 3,824,920 Users
  • 2,260,440 Discussions


Response for a successful complex POST request

juliojgs Member Posts: 596 Bronze Badge


I'm quite new to services. This question is about good practices, more than specific ords. Sorry if it is not good place.

We're setting up a REST service to insert a master-detail bunch of data in a single operation.

For example, imagine they send us info of a batch of boxes containing objects in a single json. Each box has its general properties, and the objects contained have their own properties each.

In your examples I've seen you always return the resource representation of the created entity after a post request, with the data received plus the generated id and any other metadata. That looks nice for a single box ... but in this case ... isn't it too much?

Wouldn't it be better to return a collection of single-box location headers?

We also have to decide what to do if one of the boxed object's properties fails in validation. We probably invalidate the whole box but let the other boxes pass and get created. If this behaviour is acceptable, I suppose we should return a collection indicating which boxes passed (and their locator) and which ones returned errors at box level or object level.

Best Answer

  • Hpaiss
    Hpaiss Member Posts: 39 Bronze Badge
    Answer ✓


    The REST imply some conventions like returning the new data after POST/PUT so the client can display or validate its action.

    But.... if you manage both the client code and the server code, you can set you own response policy.

    Its completely up to you.

    When working with external partners or tools you should try to stick to standards.