Skip to content
Myr

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

6 files+9 added−9 removed

modified:docs/patterns/apierrors.rst+1 added-1 removed
2 unmodified lines
34It's very common to implement RESTful APIs on top of Flask. One of the5first thing that developers run into is the realization that the builtin6exceptions 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.89The better solution than using ``abort`` to signal errors for invalid API10usage is to implement your own exception type and install an error handler11for it that produces the errors in the format the user is expecting.
52 unmodified lines
modified:docs/htmlfaq.rst+1 added-1 removed
14 unmodified lines
15However, barely any websites on the Internet are actual XHTML (which is16HTML processed using XML rules). There are a couple of major reasons17why this is the case. One of them is Internet Explorer's lack of proper18XHTML support. The XHTML spec states that XHTML must be served with the MIME19type `application/xhtml+xml`, but Internet Explorer refuses to read files19type :mimetype:`application/xhtml+xml`, but Internet Explorer refuses to read files20with that MIME type.21While it is relatively easy to configure Web servers to serve XHTML properly,22few people do. This is likely because properly using XHTML can be quite23painful.
184 unmodified lines
modified:docs/quickstart.rst+1 added-1 removed
706 unmodified lines
707708The return value from a view function is automatically converted into a709response object for you. If the return value is a string it's converted710into a response object with the string as response body, a ``200 OK``711status code and a ``text/html`` mimetype. The logic that Flask applies to711status code and a :mimetype:`text/html` mimetype. The logic that Flask applies to712converting return values into response objects is as follows:7137141. If a response object of the correct type is returned it's directly715 returned from the view.
178 unmodified lines
modified:docs/security.rst+2 added-2 removed
159 unmodified lines
160161If you know a bit of JavaScript internals you might know that it's162possible to patch constructors and register callbacks for setters. An163attacker can use this (like above) to get all the data you exported in164your JSON file. The browser will totally ignore the ``application/json``165mimetype if ``text/javascript`` is defined as content type in the script164your JSON file. The browser will totally ignore the :mimetype:`application/json`165mimetype if :mimetype:`text/javascript` is defined as content type in the script166tag and evaluate that as JavaScript. Because top-level array elements are167allowed (albeit useless) and we hooked in our own constructor, after that168page loaded the data from the JSON response is in the `captured` array.169
6 unmodified lines
modified:flask/json.py+1 added-1 removed
198 unmodified lines
199200201def 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.205206 Example usage::207
43 unmodified lines
modified:flask/wrappers.py+3 added-3 removed
96 unmodified lines
97 return self.url_rule.endpoint.rsplit('.', 1)[0]9899 @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``.103104 The :meth:`get_json` method should be used instead.105 """
5 unmodified lines
111 @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`.116117 .. versionadded:: 0.11118 """119 mt = self.mimetype
6 unmodified lines
126 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.132133 :param force: if set to ``True`` the mimetype is ignored.134 :param silent: if set to ``True`` this method will fail silently
67 unmodified lines