webapi
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)
@webapi.package('examplepackage')
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.
Installing:
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'});
req.addCallback(function(resp){
// this should return "test"
console.log(resp)
});
req.addErrback(function(resp){
// jsonrpc error objects can be handled here
console.error(resp)
});
Using the directory client
Include the compiled script.
Installing:
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):
webapi.client.loadDescription(rawRestDescription)
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);
Metadata
Release files for webapi 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| webapi-0.1.tar.gz | 20.0 kB | Details |
Release files / webapi-0.1.tar.gz
| Download URL | webapi-0.1.tar.gz |
|---|---|
| Size | 20.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3c489bd26d3d0b14cf1ffa5eac4cfd86c3a1b839b767cdc72913365f493317d8
|
|
BLAKE2b-256 checksum How to use checksums |
7f825357a60827f21b4aa4ec28f97397bcb408910a3ab4f3312b0a3306aa372f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |