0

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?

4
  • 1
    Yes why not? Get list of customers id and just name who have ordered something.. Commented Apr 2, 2015 at 9:26
  • Here you mean that you can have selective fields on a resource, right? I mean that you never can get the "creation_specific_data" field, because it is not part of the resource after creation. (At least not part of the API). Commented Apr 2, 2015 at 9:29
  • 1
    yes why not. Not necessary you need every details of customer. Commented Apr 2, 2015 at 9:32
  • Ok, thanks. I had a hunch that this is acceptable, wanted to get other opinions also. Commented Apr 2, 2015 at 9:36

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.