3

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

1 Answer 1

3

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')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.