Use HTTP 内容协商与供应商类型。如果您请求同一资源的不同表示形式,请勿使用 URL 查询参数。
请求简短的表示application/vnd.com.example.cars.short+json
of list
GET http://example.com/rest/cars
Accept: application/vnd.com.example.cars.short+json
回复:
200 OK
Content-Type: application/vnd.com.example.cars.short+json
[
{
"id": 12,
"brand": "Ford"
},
{
"id": 34,
"brand": "Volkswagen"
},
{
"id": 1234,
"brand": "Tesla"
}
]
请求长表示application/vnd.com.example.cars.long+json
单车的
GET http://example.com/rest/cars/1234
Accept: application/vnd.com.example.cars.short+json
Response
200 OK
Content-Type: application/vnd.com.example.cars.long+json
{
"id": 1234,
"brand": "Tesla",
"manufactured": "2016-03-15",
"color": "black"
}
供应商类型可用于both资源。