Genry
Genry

Reputation: 1408

REST API Design - POST different than GET

I am designing a REST API where I have the following behavior of the resource:

For creating a resource, there is initial data should be sent, which is relevant only for creation.

Which means, that the GET resource representation is different than the POST one.

Example:

POST

/api/customers

Request body:

{
    "name": "John",
    "surname": "Doe",
    "creation_specific_data": "data"
}

GET

/api/customers/1

Response body:

{
    "id": 1,
    "name": "John",
    "surname": "Doe"
}

So, as you see, the data on GET will always be partial than the one upon creation.

From my understanding, it is acceptable to supply less properties in POST and upon GET you receive more data (e.g. id auto generated by the server). The question, is it also acceptable the other way around? Supply more data upon POST and receive less data upon GET?

Upvotes: 0

Views: 78

Answers (1)

Pedro Werneck
Pedro Werneck

Reputation: 41898

Anything you do with POST is acceptable, as long as it's not replicating functionality already standardized by other method -- like using POST for simple retrieval instead of GET -- and properly documented.

Upvotes: 1

Related Questions