如何创建一个类似于:
的api调用api.add_resource(MyResource, '/myresource/<myurlparameter>')
我不知道如何从内部处理它:
class MyResource(restful.Resource):
def get(self):
print myurlparameter
return ""
另外,我注意到我只能将add_resource添加到一个级别:
api.add_resource(MyResource, '/myresource') # this works
api.add_resource(MyResource, '/myresource/test') # this this not work
答案 0 :(得分:3)
您可以在docs中找到所需的一切。
class TodoSimple(Resource):
def get(self, todo_id):
return {todo_id: todos[todo_id]}
def put(self, todo_id):
todos[todo_id] = request.form['data']
return {todo_id: todos[todo_id]}
api.add_resource(TodoSimple, '/<string:todo_id>')
api.add_resource(HelloWorld,
'/',
'/hello')