Coder Social home page Coder Social logo

sjmh / flask-jsonrpc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cenobites/flask-jsonrpc

0.0 2.0 0.0 941 KB

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

License: BSD 3-Clause "New" or "Revised" License

Makefile 0.37% Python 47.57% CSS 9.05% JavaScript 38.23% HTML 4.78%

flask-jsonrpc's Introduction

Flask JSON-RPC

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 browsable 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

https://f.cloud.github.com/assets/298350/1575590/203c595a-5150-11e3-99a0-4a6fd9bcbe52.png

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')

Write JSON-RPC methods.

@jsonrpc.method('App.index')
def index():
    return u'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"
}

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.

References

Dependencies

Project Information

Author:Cenobit Technologies, Inc.
Version:v0.3.1 of 2016/05/11
License:New BSD License

flask-jsonrpc's People

Contributors

ash211 avatar ireardon avatar jordanfung avatar langimike avatar nycholas avatar obi1kenobi avatar

Watchers

 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.