Answer the question
In order to leave comments, you need to log in
REST API and ide many-to-many
I am making a REST API for an online store.
GET /products or /products/id
returns a list of products or a single product
GET /categories or /categories/id
returns categories or an individual product
category or even not be one.
How to correctly organize this in the API?
Answer the question
In order to leave comments, you need to log in
It seems to me that we should not complicate the API and return product categories (their id and name, for example) along with the product, using the /products/id link. And if there is a real need to get some properties of the product separately (only price and description, for example), add the parameter ?fields=field1,field2
Designing the API is not based on some abstract considerations, but on the planned use cases, and for reasons of simplicity.
since you started like this, then continue like this:
GET /product_categories/id
GET /category_prodycts/id
API does not have to be competent, first of all it should be similar (see PHP functions, everyone is used to chaotic typing, and this is even it doesn’t bother, but for the parameters of each function, the majority climbs into the docks or uses hints, no one can learn this)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question