Documentation updates

This commit is contained in:
Adam Byrtek 2015-04-12 23:34:03 +01:00 committed by Markus Unterwaditzer
parent 5575faad92
commit 5ebdd5dd74
3 changed files with 6 additions and 4 deletions

View file

@ -29,7 +29,7 @@ Incoming Request Data
--------------------- ---------------------
.. autoclass:: Request .. autoclass:: Request
:members: :members: is_json, get_json
.. attribute:: form .. attribute:: form
@ -141,7 +141,7 @@ Response Objects
---------------- ----------------
.. autoclass:: flask.Response .. autoclass:: flask.Response
:members: set_cookie, data, mimetype :members: set_cookie, data, mimetype, is_json, get_json
.. attribute:: headers .. attribute:: headers

View file

@ -362,7 +362,7 @@ Testing JSON APIs
Flask has great support for JSON, and is a popular choice for building REST Flask has great support for JSON, and is a popular choice for building REST
APIs. Testing both JSON requests and responses using the test client is very APIs. Testing both JSON requests and responses using the test client is very
convenient: convenient::
from flask import jsonify from flask import jsonify
@ -371,12 +371,14 @@ convenient:
json_data = request.get_json() json_data = request.get_json()
email = json_data['email'] email = json_data['email']
password = json_data['password'] password = json_data['password']
return jsonify(token=generate_token(email, password)) return jsonify(token=generate_token(email, password))
with app.test_client() as c: with app.test_client() as c:
email = 'john@example.com' email = 'john@example.com'
password = 'secret' password = 'secret'
resp = c.post('/api/auth', json={'login': email, 'password': password}) resp = c.post('/api/auth', json={'login': email, 'password': password})
json_data = resp.get_json() json_data = resp.get_json()
assert verify_token(email, json_data['token']) assert verify_token(email, json_data['token'])

View file

@ -57,7 +57,7 @@ class JSONMixin(object):
return self.data return self.data
def get_json(self, force=False, silent=False, cache=True): def get_json(self, force=False, silent=False, cache=True):
"""Parses the incoming JSON request data and returns it. By default """Parses the JSON request/response data and returns it. By default
this function will return ``None`` if the mimetype is not this function will return ``None`` if the mimetype is not
:mimetype:`application/json` but this can be overridden by the :mimetype:`application/json` but this can be overridden by the
``force`` parameter. If parsing fails the ``force`` parameter. If parsing fails the