FAQ
Composite Keys
Question: Composite Keys
Many existing web applications have to deal with mutliple ids (Composite Keys). Let’s say, order 4711 and order line 42, whereas the order lines are exposed via the rest API. How do we apply this to the REST URL structure?
1) orderlines/4711/42
or
2) orderlines(4711,42)
Are there any guidelines?
Answer
That is a good example for a subresource. You should design it like this:
orders/4711/orderlines/42
If you want to expose orderlines as a top level resource and the orderline key is not unique over all orderlines in your internal model, you should create a separate unique key (e.g. a UUID) as additional key.
orderlines/56e94f2b-25ac-4c58-9828-f63b66220999