Giter Site home page Giter Site logo

yonglehou / flask-json Goto Github PK

View Code? Open in Web Editor NEW

This project forked from skozlovf/flask-json

0.0 2.0 0.0 317 KB

Flask-JSON is a Flask extension providing better JSON support.

Home Page: http://flask-json.readthedocs.org

License: Other

Python 100.00%

flask-json's Introduction

Flask-JSON

image

Flask-JSON is a simple extension that adds better JSON support to Flask application.

Features:

  • Works on python 2.6, 2.7, 3.3+ and Flask 0.10+.
  • More ways to generate JSON responses (comparing to plain Flask).
  • Extended JSON encoding support.

Usage

Here is fast example:

from datetime import datetime
from flask import Flask
from flask_json import FlaskJSON, JsonError, json_response, as_json

app = Flask(__name__)
FlaskJSON(app)


@app.route('/get_time')
def get_time():
    return json_response(time=datetime.utcnow())


@app.route('/get_time_and_value')
@as_json
def get_time_and_value():
    return dict(time=datetime.utcnow(), value=12)


@app.route('/raise_error')
def raise_error():
    raise JsonError(description='Example text.', code=123)


if __name__ == '__main__':
    app.run()

Responses:

GET /get_time HTTP/1.1

HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 60

{
  "status": 200,
  "time": "2015-04-14T13:17:16.732000"
}
GET /raise_error HTTP/1.1

HTTP/1.0 400 BAD REQUEST
Content-Type: application/json
Content-Length: 70

{
  "code": 123,
  "description": "Example text.",
  "status": 400
}

Documentation

Documentation is available on pythonhosted and Read the Docs.

flask-json's People

Contributors

skozlovf avatar craig552uk avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.