Im refactoring my leisure api server to use Flask-RESTful, and im that has some doubts in some special cases when I need to get a list of resources belonging to another. Something like that:
/api/v1/users/john/orders
How would you develop this? Because, if I have a resource called "Orders", I need to know from which user I should receive orders. But how can I tell the resource about the user? I do not see any __ init __ method where I can specify parameters for resources.
I thought about doing something similar when registering the Orders resource:
api.add_resources(Orders, '/api/v1/users/<string:username>/orders')
But how can I access the line : username in the Orders resource?
I think one solution would be to make:
api.add_resources(Orders, '/api/v1/orders/')
and send the request parameters, indicating the user from whom I want to receive orders, but I wanted to know if it is possible to do something similar to the above example.
source share