Kevin
Kevin

Reputation: 1133

Accessing request payload from RESTful calls in Tornado Web

I have a basic app set up using Backbone.js and Tornado Web. When I save my Backbone model, it fires off a POST request to one of my handlers' post methods. I want to access the variables inside the payload but the arguments dictionary is empty.


Request Payload
{"text":"dghjdg","date":"2012-02-05T11:23:46.105Z","author":"Kevin"}
Response Headersview parsed
HTTP/1.1 200 OK
Content-Length: 0
Content-Type: text/html; charset=UTF-8
Server: TornadoServer/2.2

It seems as if self.get_argument in the handler only collects data from Form Data in the request header and not the Request Payload part. How can I access any of the variables in the Request Payload?

Upvotes: 1

Views: 1377

Answers (1)

jholster
jholster

Reputation: 5136

Request body (or payload) can be accessed using self.request.body. Obviously you must decode the JSON format, e.g. json.loads(self.request.body).

Upvotes: 3

Related Questions