在Flask-RESTful中,我们添加如下的api路线
api.add_resource(CuteKitty,'/api/kitty')
class CuteKitty(Resource):
def get(self): return {}
def post(self): return {}
def put(self): return {}
def delete(self): return None, 204
Run Code Online (Sandbox Code Playgroud)
所以GET /api/kitty- >到CuteKitty.get()方法; 像所有HTTP动词一样
让我们说我需要为我的api消费者提供一个可爱的api
POST /api/kitty/drink/milk ---> CuteKitty.drink(what="milk")
POST /api/kitty/meow ---> CuteKitty.meow()
Run Code Online (Sandbox Code Playgroud)
我怎样才能实现上述路由 api.add_resource
class CuteKitty(Resource):
def get(self): return {}
def post(self): return {}
def put(self): return {}
def delete(self): return None, 204
def drink(self,what="milk"): return {}
def meow(self): return {}
Run Code Online (Sandbox Code Playgroud)
像智者一样如何添加路线/api/kitty/<int:kitty_id>/habits- >CuteKitty.habits(kitty_id)