scoots
scoots

Reputation: 715

Using a RESTFUL PUT, how should parent/child entities be updated (or informed)?

For a simple example, I'll use tires and cars. I intend to execute a PUT to increase the price of a tire. The UI also contains cars that use the tires being updated, therefore requiring a price update of their own.

Is it appropriate for the original PUT request to contain car pricing in its response? If not, how is this typically solved?

Upvotes: 2

Views: 1678

Answers (1)

Brian Kelly
Brian Kelly

Reputation: 19295

A PUT to update a /tire price should absolutely not return details of how it updated a different resource like a /car. Doing so would co-mingle the two entities and make your resource representations overly complex. It would also make "atomic" updates of individual resources difficult for clients.

The PUT response should only tell you whether or not the update succeeded on the /tire resource, and perhaps provide the new representation of the tire in the response content. Once the PUT call to the tire has returned, the client (your UI) can then GET the /car once more and it will see a new price for the overall car that takes into account the new tire cost.

Upvotes: 2

Related Questions