• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

Flask_JSON.egg-info/H03-May-2022-10575

LICENSEH A D02-Oct-20161.4 KiB2821

MANIFEST.inH A D02-Oct-201627 21

PKG-INFOH A D23-Aug-20193 KiB10575

README.rstH A D24-Oct-20181.6 KiB8455

flask_json.pyH A D23-Aug-201921.5 KiB675500

setup.cfgH A D23-Aug-201963 85

setup.pyH A D03-May-20221.4 KiB4841

README.rst

1Flask-JSON
2==========
3
4.. image:: https://travis-ci.org/skozlovf/flask-json.png?branch=master
5   :target: https://travis-ci.org/skozlovf/flask-json
6
7Flask-JSON is a simple extension that adds better JSON support to Flask
8application.
9
10Features:
11
12* Works on python 2.6, 2.7, 3.3+ and Flask 0.10+.
13* More ways to generate JSON responses (comparing to plain Flask).
14* Extended JSON encoding support.
15
16Usage
17-----
18
19Here is fast example:
20
21.. code-block:: python
22
23    from datetime import datetime
24    from flask import Flask
25    from flask_json import FlaskJSON, JsonError, json_response, as_json
26
27    app = Flask(__name__)
28    FlaskJSON(app)
29
30
31    @app.route('/get_time')
32    def get_time():
33        return json_response(time=datetime.utcnow())
34
35
36    @app.route('/get_time_and_value')
37    @as_json
38    def get_time_and_value():
39        return dict(time=datetime.utcnow(), value=12)
40
41
42    @app.route('/raise_error')
43    def raise_error():
44        raise JsonError(description='Example text.', code=123)
45
46
47    if __name__ == '__main__':
48        app.run()
49
50Responses:
51
52.. code-block:: json
53
54    GET /get_time HTTP/1.1
55
56    HTTP/1.0 200 OK
57    Content-Type: application/json
58    Content-Length: 60
59
60    {
61      "status": 200,
62      "time": "2015-04-14T13:17:16.732000"
63    }
64
65.. code-block:: json
66
67    GET /raise_error HTTP/1.1
68
69    HTTP/1.0 400 BAD REQUEST
70    Content-Type: application/json
71    Content-Length: 70
72
73    {
74      "code": 123,
75      "description": "Example text.",
76      "status": 400
77    }
78
79Documentation
80-------------
81
82Documentation is available on
83`Read the Docs <http://flask-json.readthedocs.io>`_.
84