Skip to content

A basic JSON-RPC implementation for your Flask-powered sites

License

Unknown, BSD-3-Clause licenses found

Licenses found

Unknown
LICENSE
BSD-3-Clause
COPYING
Notifications You must be signed in to change notification settings

CyrilCh/flask-jsonrpc

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Status

Flask JSON-RPC

A basic JSON-RPC implementation for your Flask-powered sites.

Some reasons you might want to use:

  • Simple, powerful, flexible and pythonic API.
  • Support JSON-RPC 2.0 version.
  • Support python 3.6 or later.
  • The web browsable API.
  • Run-time type checking functions defined with PEP 484 argument (and return) type annotations.
  • Extensive documentation, and great community support.

There is a live example API for testing purposes, available here.

Below: Screenshot from the browsable API

Web browsable API

Adding Flask JSON-RPC to your application

  1. Installation
    $ pip install Flask-JSONRPC

or

    $ git clone git://github.com/cenobites/flask-jsonrpc.git
    $ cd flask-jsonrpc
    $ python setup.py install
  1. Getting Started

Create your application and initialize the Flask-JSONRPC.

    from flask import Flask
    from flask_jsonrpc import JSONRPC

    app = Flask(__name__)
    jsonrpc = JSONRPC(app, '/api', enable_web_browsable_api=True)

Write JSON-RPC methods.

    @jsonrpc.method('App.index')
    def index() -> str:
        return 'Welcome to Flask JSON-RPC'

All code of example run.py.

  1. Running
    $ python run.py
     * Running on http://0.0.0.0:5000/
  1. Testing
    $ curl -i -X POST \
       -H "Content-Type: application/json; indent=4" \
       -d '{
        "jsonrpc": "2.0",
        "method": "App.index",
        "params": {},
        "id": "1"
    }' http://localhost:5000/api
    HTTP/1.0 200 OK
    Content-Type: application/json
    Content-Length: 77
    Server: Werkzeug/0.8.3 Python/2.7.3
    Date: Fri, 14 Dec 2012 19:26:56 GMT

    {
      "jsonrpc": "2.0",
      "id": "1",
      "result": "Welcome to Flask JSON-RPC"
    }

References

About

A basic JSON-RPC implementation for your Flask-powered sites

Resources

License

Unknown, BSD-3-Clause licenses found

Licenses found

Unknown
LICENSE
BSD-3-Clause
COPYING

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 44.7%
  • JavaScript 40.4%
  • CSS 9.6%
  • HTML 5.1%
  • Makefile 0.2%