Saumil Patel Saumil Patel - 1 year ago 114
reST (reStructuredText) Question

Nested router vs filters

I'm very new to API implementation from ground up and I needed some advice on what the standard or the best approach in my API structure is.

Currently my implementation includes nested routers (drf-nested-routers package) such as


Now as I dig deeper in django I've uncovered that there are filters that allow me to do the exact same operation above with a little less code like this


My question is which one is best practice and why?

Answer Source

If a product is always related to a store (which seems to be the case, given the names), then it's considered a best practice for REST, to maintain an hierarchical structure by making products a subresource of stores. Thus I would suggest you to follow the first aforementioned approach.

The filtering should be used to filter resources based on some internal characteristics (e.g class attributes), not based on relations to other resources.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download