假设我需要为客户创建一个货件,并且该货件需要一个地址。这两个资源都需要创建。创建REST资源:撰写或分离?
在REST设计中,哪种方法是首选?为什么?
# One request that in-lines the address.
POST /shipments
{
"shipment": {
"customer_id": 1,
"address": {
"city": "Toronto",
...
}
}
}
VS
# Two requests, first creating the address, then passing an id.
POST /addresses
{
"address": {
"customer_id": 1,
"city": "Toronto",
...
}
}
POST /shipment
{
"shipment": {
customer_id: 1,
address_id: 100
}
}