docs: :mimetype:`application/json`
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by defuz · committed by defuz · parent 663802e · Browse files · 6 files·+9 added−9 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+9 added−9 removed
- other:+9 added−9 removed
Provenance
- Commit
d4b9b98- Tree
60c8b53- Author
defuz <defuz.net@gmail.com>- Committer
defuz <defuz.net@gmail.com>- Parent
663802e
6 files changed+9 added−9 removed
modified:docs/patterns/apierrors.rst+1 added-1 removed
2 unmodified lines3 4 It's very common to implement RESTful APIs on top of Flask. One of the5 first thing that developers run into is the realization that the builtin6 exceptions are not expressive enough for APIs and that the content type of7-``text/html`` they are emitting is not very useful for API consumers.7+:mimetype:`text/html` they are emitting is not very useful for API consumers.8 9 The better solution than using ``abort`` to signal errors for invalid API10 usage is to implement your own exception type and install an error handler11 for it that produces the errors in the format the user is expecting.52 unmodified linesmodified:docs/htmlfaq.rst+1 added-1 removed
14 unmodified lines15 However, barely any websites on the Internet are actual XHTML (which is16 HTML processed using XML rules). There are a couple of major reasons17 why this is the case. One of them is Internet Explorer's lack of proper18 XHTML support. The XHTML spec states that XHTML must be served with the MIME19-type `application/xhtml+xml`, but Internet Explorer refuses to read files19+type :mimetype:`application/xhtml+xml`, but Internet Explorer refuses to read files20 with that MIME type.21 While it is relatively easy to configure Web servers to serve XHTML properly,22 few people do. This is likely because properly using XHTML can be quite23 painful.184 unmodified linesmodified:docs/quickstart.rst+1 added-1 removed
706 unmodified lines707 708 The return value from a view function is automatically converted into a709 response object for you. If the return value is a string it's converted710 into a response object with the string as response body, a ``200 OK``711-status code and a ``text/html`` mimetype. The logic that Flask applies to711+status code and a :mimetype:`text/html` mimetype. The logic that Flask applies to712 converting return values into response objects is as follows:713 714 1. If a response object of the correct type is returned it's directly715 returned from the view.178 unmodified linesmodified:docs/security.rst+2 added-2 removed
159 unmodified lines160 161 If you know a bit of JavaScript internals you might know that it's162 possible to patch constructors and register callbacks for setters. An163 attacker can use this (like above) to get all the data you exported in164-your JSON file. The browser will totally ignore the ``application/json``165-mimetype if ``text/javascript`` is defined as content type in the script164+your JSON file. The browser will totally ignore the :mimetype:`application/json`165+mimetype if :mimetype:`text/javascript` is defined as content type in the script166 tag and evaluate that as JavaScript. Because top-level array elements are167 allowed (albeit useless) and we hooked in our own constructor, after that168 page loaded the data from the JSON response is in the `captured` array.169 6 unmodified linesmodified:flask/json.py+1 added-1 removed
198 unmodified lines199 200 201 def jsonify(*args, **kwargs):202 """Creates a :class:`~flask.Response` with the JSON representation of203- the given arguments with an `application/json` mimetype. The arguments203+ the given arguments with an :mimetype:`application/json` mimetype. The arguments204 to this function are the same as to the :class:`dict` constructor.205 206 Example usage::207 43 unmodified linesmodified:flask/wrappers.py+3 added-3 removed
96 unmodified lines97 return self.url_rule.endpoint.rsplit('.', 1)[0]98 99 @property100 def json(self):101- """If the mimetype is `application/json` this will contain the101+ """If the mimetype is :mimetype:`application/json` this will contain the102 parsed JSON data. Otherwise this will be ``None``.103 104 The :meth:`get_json` method should be used instead.105 """5 unmodified lines111 @property112 def is_json(self):113 """Indicates if this request is JSON or not. By default a request114 is considered to include JSON data if the mimetype is115- ``application/json`` or ``application/*+json``.115+ :mimetype:`application/json` or :mimetype:`application/*+json`.116 117 .. versionadded:: 0.11118 """119 mt = self.mimetype6 unmodified lines126 def get_json(self, force=False, silent=False, cache=True):127 """Parses the incoming JSON request data and returns it. If128 parsing fails the :meth:`on_json_loading_failed` method on the129 request object will be invoked. By default this function will130- only load the json data if the mimetype is ``application/json``130+ only load the json data if the mimetype is :mimetype:`application/json`131 but this can be overridden by the `force` parameter.132 133 :param force: if set to ``True`` the mimetype is ignored.134 :param silent: if set to ``True`` this method will fail silently67 unmodified lines