Document request.body
as a way to get raw POST body
This commit is contained in:
parent
8f6e5a1263
commit
2312a176fe
|
@ -8,6 +8,7 @@ The following request variables are accessible as properties:
|
||||||
`request.json` (any) - JSON body
|
`request.json` (any) - JSON body
|
||||||
`request.args` (dict) - Query String variables. Use getlist to get multiple of the same name
|
`request.args` (dict) - Query String variables. Use getlist to get multiple of the same name
|
||||||
`request.form` (dict) - Posted form variables. Use getlist to get multiple of the same name
|
`request.form` (dict) - Posted form variables. Use getlist to get multiple of the same name
|
||||||
|
`request.body` (bytes) - Posted raw body. To get the raw data, regardless of content type
|
||||||
|
|
||||||
See request.py for more information
|
See request.py for more information
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@ See request.py for more information
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from sanic import Sanic
|
from sanic import Sanic
|
||||||
from sanic.response import json
|
from sanic.response import json, text
|
||||||
|
|
||||||
@app.route("/json")
|
@app.route("/json")
|
||||||
def post_json(request):
|
def post_json(request):
|
||||||
|
@ -40,4 +41,9 @@ def post_json(request):
|
||||||
@app.route("/query_string")
|
@app.route("/query_string")
|
||||||
def query_string(request):
|
def query_string(request):
|
||||||
return json({ "parsed": True, "args": request.args, "url": request.url, "query_string": request.query_string })
|
return json({ "parsed": True, "args": request.args, "url": request.url, "query_string": request.query_string })
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/users", methods=["POST",])
|
||||||
|
def create_user(request):
|
||||||
|
return text("You are trying to create a user with the following POST: %s" % request.body)
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue
Block a user