Closed
Description
Python runtime of Nirum has to provide a WSGI adaptor which takes an RPC service and serves it. See also nirum-lang/nirum#25.
The generated service code will look like the following:
from nirum.rpc import WsgiApp, Service
class CustomerService(Service):
# GET /tokens/:token/key -> get_key_by_token
# GET /api/group_tokens/?arg=token -> group_tokens
# POST /jsonrpc
# {"method": "group_tokens", "param": {"abc", "def"}}
# GET /api/get_key_by_token/?arg=token -> get_key_by_token
__nirum_service_methods__ = {'get_key_by_token', 'group_tokens'}
__nirum_http_routing__ = {
'get_key_by_token': ('get', '/tokens/:token/key/'),
}
def get_key_by_token(token: 'Token') -> 'Key':
raise NotImplementedError('get_key_by_token')
def group_tokens(
token: typing.AbstractSet['Token']
) -> typing.AbstractSet[typing.AbstractSet['Token']]:
raise NotImplementedError('group_tokens')
class CustomerServiceImpl(CustomerService):
pass
app = WsgiApp(CustomerService()) # wsgi app
where the Nirum IDL looks like the following:
boxed token (uuid);
union key = phone (text phone_number)
| qr-code (text url)
| credit-card (blob hash)
;
service customer (
[http-get: "/tokens/:token/key/"]
key get-key-by-token (token token),
{{token}} group-tokens ({token} tokens),
);