I have a situation : Category - Master data with different types. Order - Has a reference to Category. It is a one-to-one mapping from Order to Category. Order table has a foreign key column to Category. Now api to get Orders
/users/orders
Will the return type as
{ "name: "abc", "categoryId" : 23 }
will be fine or should we return the json as
{ "name: "abc", "category" : "CAT-A" }
We also have a create/update Order use case with client knowing the category. We need a api to post new Order with a Category. Should it be something like this?
1. post /api/orders { "categoryId" : 23, ....}
Or something like this?
2. post /api/orders/category/23/order
first, use identifiers (or links!):
{ "name: "abc", "categoryId" : 23 }
or
{ "name: "abc", "category" : "/api/categories/23" }
not names (because those could change from time to time)
{ "name: "abc", "category" : "CAT-A" }
For the posting of orders I would suggest to use
post /api/orders { "categoryId" : 23, ....}
just because you are adding an order on the order resource. The order should already have a category referenced (or linked!).
This approach
post /api/orders/category/23/order
would also be okay. But the client would need to build an url with information that is already contained in the request body, so things only got a little more complicated (what if the categories in url and request body are not the same? What if the category in the request body is missing? Is the request still valid in this case?)