Skip to main content

A framework to build web (json-rpc) APIs.

Project description


A framework to build web (json-rpc) APIs.

Quick Start

Defining messages and a service:

class TestRequest(messages.Message):
    string = messages.StringField(1)

class TestResponse(messages.Message):
    string = messages.StringField(1)

class ExampleService(object):

    @webapi.method(TestRequest, TestResponse, 'examplemethod')
    def test(self, request):
        """ an identity function"""
        assert isinstance(request, TestRequest)
        return TestResponse(string=request.string)

Building a wsgi application:

API = webapi.api([ExampleService], 'exampleapi', 'v1')

routes = [
    webapp2.Route('/rpc', webapi.rpc_handler(API))
app = webapp2.WSGIApplication(routes)

The api should be available at /rpc.

A method exampleapi.examplepackage.examplemethod should be available to callers.

Exporting a discovery application

Define in python:

API = webapi.api([TestService], 'testapi', 'v1')

api_directory_app = webapi.APIDirectory([API])

Register with app.yaml to match the path /discovery/.*.

Using the javascript client.

Using the basic client

Include the compiled script.


var RPC_URL = '/rpc';

webapi.client.install(new webapi.RpcClient(RPC_URL));

Calling a method:

var METHOD = 'exampleapi.examplepackage.examplemethod'

var req = webapi.client.rpc(METHOD, {'string': 'test'});

    // this should return "test"

    // jsonrpc error objects can be handled here

Using the directory client

Include the compiled script.


var RPC_URL = '/rpc';

webapi.client.install(new webapi.DiscoveryClient());

Loading an api (from a directory):

webapi.client.load(apiName, apiVersion, root)

Loading a rest description (from a json object):


After loading an api its methods will be exported to the webapi namespace. For example:

var request = webapi.apiname.package.method();

Executing an rpc method (manually):

var request = webapi.client.rpc(methodId, params);

Project details

Release history Release notifications | RSS feed

This version


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

webapi-0.1.tar.gz (20.0 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page