From 5ebdd5dd7455ca4a4c8ba1aff727f40e77a11c08 Mon Sep 17 00:00:00 2001 From: Adam Byrtek Date: Sun, 12 Apr 2015 23:34:03 +0100 Subject: [PATCH] Documentation updates --- docs/api.rst | 4 ++-- docs/testing.rst | 4 +++- flask/wrappers.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index e72c9ace..9344f7aa 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -29,7 +29,7 @@ Incoming Request Data --------------------- .. autoclass:: Request - :members: + :members: is_json, get_json .. attribute:: form @@ -141,7 +141,7 @@ Response Objects ---------------- .. autoclass:: flask.Response - :members: set_cookie, data, mimetype + :members: set_cookie, data, mimetype, is_json, get_json .. attribute:: headers diff --git a/docs/testing.rst b/docs/testing.rst index 8b9af8bd..07c9aaf5 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -362,7 +362,7 @@ Testing JSON APIs 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 -convenient: +convenient:: from flask import jsonify @@ -371,12 +371,14 @@ convenient: json_data = request.get_json() email = json_data['email'] password = json_data['password'] + return jsonify(token=generate_token(email, password)) with app.test_client() as c: email = 'john@example.com' password = 'secret' resp = c.post('/api/auth', json={'login': email, 'password': password}) + json_data = resp.get_json() assert verify_token(email, json_data['token']) diff --git a/flask/wrappers.py b/flask/wrappers.py index ac771650..a91d82c0 100644 --- a/flask/wrappers.py +++ b/flask/wrappers.py @@ -57,7 +57,7 @@ class JSONMixin(object): return self.data 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 :mimetype:`application/json` but this can be overridden by the ``force`` parameter. If parsing fails the