In a shopping cart application, suppose I have an endpoint for an endpoint for an /product/
for products that can be bought and a /cartitem/
for items in a shopping cart. Example of GET /product/2 response
{
"sku": "12345"
"name":"mars bar"
}
Example of a GET /cartitem/56
{
"quantity": 4
"sku": "12345"
"name":"mars bar"
}
When adding a cartitem, I will do a POST to /cartitem/ but instead of having to pass up the entire body, I'd like to able to just post a reference to the product
POST /cartitem
BODY:
{
"quantity": "4"
"product":"/product/2"
}
instead of having to do:
POST /cartitem/
{
"quantity": 4
"sku": "12345"
"name":"mars bar"
}
Note, I never want to have:
GET
{
"quantity": "4"
"product":"/product/2"
}
Reason is because there are multiple to ways to add a cartitem, sometimes you will have a product, sometimes you want. I want the response to not have to reference a product URI, but I want the POST to be allowed to reference it to make it easier for some clients.
Is that okay?
Thanks