Im refactoring my rest api server to use Flask-RESTful, and im having some doubt about some particular cases where i need to get a list of resources that belong to another. Some thing like this:
/api/v1/users/john/orders
How would you design this? Because if I have a resource called Orders, I need to know from which user i have to get the orders from. But how can i let the resource know about the user? i dont see any __ init __ method where i can specify parameters to the resources.
I thought about doing something like this when registering the Orders resource:
api.add_resources(Orders, '/api/v1/users/<string:username>/orders')
But the how can i access the string:username in the Orders resource??
I guess one solution would be to do:
api.add_resources(Orders, '/api/v1/orders/')
and send query parameters specifying the user i want to get the orders from, but I wanted to know if its possible to do something like the above example.