Question

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
Was it helpful?

Solution

You can find everything you need in the docs.

Parameter in requests

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>')

Few endpoints

api.add_resource(HelloWorld,
    '/',
    '/hello')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top