Flask-RESTful is intended to implement the RESTful API, in particular by interpreting the HTTP request method. Drink and Meow, obviously, are not HTTP methods (at least they are not specified in the specification - I will leave this at the same time), Flask-RESTful is not connected with the drink and meow in the resource.
The obvious answer to this is to define several API routes:
api.add_resource(CuteKitty, '/kitty/<int:kitty_id>/') api.add_resource(DrinkingKitty, '/kitty/<int:kitty_id>/drink/<what>') api.add_resource(MeowingKitty, '/kitty/<int:kitty_id>/meow/')
A less obvious way is to create a frankenresource:
# still allow requests to hit just get/post/etc without invoking anything else api.add_resource(CuteKitty, '/kitty/<int:kitty_id>/') api.add_resource(CuteKitty, '/kitty/<int:kitty_id>/<task>/<path:args>/')
And then break the arguments with split('/') and invoke the task with them. Alternatively, you can set them as URL arguments ( /endpoint/?task=drink&what=milk ) - this is still a valid RESTful architecture.
You can also subclass the resource class and implement the desired functionality yourself - in this case, I would recommend to see how Flask-Classy implements this. Or you can pick up Flask-Classy and play with it and see how you like it; however, for the direct API, I believe that RESTful brings a lot more than Classy.
source share