Adds JSONRPC support to Flask.
Project description
A basic JSON-RPC implementation for your Flask-powered sites based on django-json-rpc.
Some reasons you might want to use:
Simple, powerful, flexible and pythonic API.
Support python 2.7, 3.3 or later
The Web browseable API.
Support for authentication.
Proxy to test your JSON Service.
Run-time type checking.
Extensive documentation, and great community support.
For support python 2.6.5+ or earlier use the branch py2k.
There is a live example API for testing purposes, available here.
Below: Screenshot from the browsable API
Adding Flask JSON-RPC to your application
Installation
$ pip install Flask-JSONRPC
or
$ git clone git://github.com/cenobites/flask-jsonrpc.git $ cd flask-jsonrpc $ python setup.py install
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')
Write JSON-RPC methods.
@jsonrpc.method('App.index')
def index():
return u'Welcome to Flask JSON-RPC'
All code of Example run.py.
Running
$ python run.py * Running on http://0.0.0.0:5000/
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"
}
Testing your service
You can test your service using the provided web browsable API, available at http://localhost:5000/api/browse (if using the url patterns from above) or with the included ServiceProxy:
>>> from flask_jsonrpc.proxy import ServiceProxy
>>> server = ServiceProxy('http://localhost:5000/api')
>>>
>>> server.App.index()
{'jsonrpc': '2.0', 'id': '91bce374-462f-11e2-af55-f0bf97588c3b', 'result': 'Welcome to Flask JSON-RPC'}
We add the jsonrpc_version variable to the request object. It be either ‘1.0’, ‘1.1’ or ‘2.0’. Arg.
For more tests see Examples.
Referencies
Dependecies
Python (2.6.5+), (2.7, 3.3) or later (http://www.python.org)
Flask 0.10 or later (http://flask.pocoo.org)
Project Information
- Author:
Cenobit Technologies, Inc.
- Version:
v0.3 of 2015/08/10
- License:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file Flask-JSONRPC-0.3.tar.gz.
File metadata
- Download URL: Flask-JSONRPC-0.3.tar.gz
- Upload date:
- Size: 679.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5baf70bf9cf955e95c02316982026a122b89a5f4c78c5b26f9f476abdb3e13bc
|
|
| MD5 |
a5beca4c3a882315f9b81acb57e83c68
|
|
| BLAKE2b-256 |
fb92e31d27e75fddf9fd1f3c6ace653b3fd9801d1468f6b9fa4c8a8595fad479
|