Reputation: 2141
How do I create an api call that does something like:
api.add_resource(MyResource, '/myresource/<myurlparameter>')
It is not clear how I can handle it from within:
class MyResource(restful.Resource):
def get(self):
print myurlparameter
return ""
Also, I noticed I can only add_resource to one level:
api.add_resource(MyResource, '/myresource') # this works
api.add_resource(MyResource, '/myresource/test') # this this not work
Upvotes: 3
Views: 4780
Reputation: 6162
You can find everything you need in the 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')
Upvotes: 3