[英]REST API Design - POST different than GET
I am designing a REST API where I have the following behavior of the resource: 我正在设计一个REST API,该资源具有以下行为:
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. 这意味着GET
资源表示与POST
资源表示不同。
Example: 例:
/api/customers
Request body:
{
"name": "John",
"surname": "Doe",
"creation_specific_data": "data"
}
/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. 因此,如您所见, GET
上的数据将始终是部分数据,而不是创建时的数据。
From my understanding, it is acceptable to supply less properties in POST
and upon GET
you receive more data (eg id auto generated by the server). 据我了解,在POST
提供较少的属性是可以接受的,而在GET
您会收到更多的数据(例如,服务器自动生成的ID )。 The question, is it also acceptable the other way around? 问题是,反过来也可以接受吗? Supply more data upon POST
and receive less data upon GET
? POST
提供更多数据,而GET
接收较少数据?
你做任何事情POST
是可以接受的,只要它不复制已经被其他方法标准化的功能-就像使用POST
进行简单的检索,而不是GET
-与适当的记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.