Search code examples
jsonpython-2.7httprequestputwebapp2

webapp2 how to access PUT data


I am using webapp2 to make a small api.

So for example if I have:

import webapp2

class Test(webapp2.RequestHandler):

    def put(self):
        self.response.write("this was a test")

app = webapp2.WSGIApplication([
    ('/test', Test)
])

And I do a request through curl:

curl --request PUT --header "Content-Type: application/json" --data '{"content": "test"}' http://localhost:8080/test

How would I go about accessing the data '{"content": "test"}' that was passed in?


Solution

  • All request data would be somewhere in self.request, so in this case take a look at self.request.body to find the request's contents and check out the documentation's Common Request attributes section to see the rest of the options.

    You may also want to consider looking at the entire self object in a debugger to find out about more interesting properties it has.