peflorencio
peflorencio

Reputation: 2472

REST - Should the resource structure match between all verbs?

A friend of mine is developing a RESTful HTTP API. He showed his solution to an architect of the company who said that his solution was wrong because the resource exposed in a GET didn't have the same structure as the resource in the POST. That is, the resource returned on a GET had less fields than the one passed on a POST. The architect gave no arguments besides saying that this is not RESTful.

Is there any rule in REST architecture saying that the resource structure should be the same for any verb? If yes, why is this recommended?

Thanks

Upvotes: 1

Views: 52

Answers (1)

hakany
hakany

Reputation: 7254

Architectural contrains for REST are described here: https://en.wikipedia.org/wiki/Representational_state_transfer#Architectural_constraints

None of them describes something that the a response types (GET, POST, ...) should have same structure, however a GET result should have enough information to be able to do a POST or DELETE request (Manipulation of resources through representations). That's because you won't be able to modify or delete you resource if the required parameters for modify or delete are not able; for example from your GET you retrieve values x and y but also need value z to be able to do a POST, how would you be able to modify this resource?

Hope this answers your question.

Upvotes: 2

Related Questions