simpleapi is an easy to use, consistent, transparent and portable way of providing an API. It supports several transport formats (e. g. json, jsonp, xml, yaml) and provides server (django, flask) and client libraries (PHP, Python) to interact seamlessly. You can also use nearly every Ajax framework (e. g. jQuery, ExtJS, etc.) to access the API.
To install, simply run:
# pip install --upgrade simpleapi
The source is available on GitHub. You can als follow simpleapi on twitter @simpleapi to stay up-to-date.
Warning
This documentation is uncomplete and will be finished over the next few weeks. Please be patient.
from simpleapi import Namespace
class Calculator(Namespace):
def add(self, a, b):
return a + b
add.published = True
from simpleapi import Route
from handlers import Calculator
urlpatterns = patterns('',
(r'^api/calculator/$', Route(Calculator))
)
from simpleapi import Route
from handlers import Calculator
from flask import Flask
app = Flask(__name__)
app.route('/api/')(Route(Calculator, framework='flask'))
if __name__ == '__main__':
app.run()
from simpleapi import Client
calculator = Client(ns='http://localhost:8888/api/calculator/')
print "5 + 3 =", calculator.add(a=5, b=3)
<?php
$calculator = new Client(ns='http://localhost:8888/api/calculator/');
print("5 + 3 ".$calculator->add(array('a'=>5, 'b'=>3)));
?>
jQuery.get(
"/api/calculator/",
{_call: 'add', a: 5, b: 3},
function (result) {
alert('5 + 3 = ' + result);
}
)