I have products and categories represented by a REST API.
Products are children of categories i.e. /categories/{category_id}/products/{product_id}
Each category can also be child of another category. E.g: Transport -> Cars -> Sports cars -> Aston Martins.
How would I go about representing this RESTfully?
So far I have only come up with: /categories/{category_id}/categories/{category_id}/categories/{category_id}/
...
but I don't like how big the URI becomes assuming I can have many levels of subcategory.
You shouldn't have to use a really long URL to uniquely identify a vehicle. Can a truck and a car have the same id? Can a Toyota and a Ford car have the same id?
Transport -> Cars -> Sports cars -> Aston Martins
could be as easy as:
or:
or if you're viewing a filtered down collection based on some criteria:
The fact that this vehicle is an Aston Martin, a car and a Sport Car doesn't have to be reflected in the URL.