Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSGI adaptor to serve RPC services #9

Closed
kanghyojun opened this issue Jul 26, 2016 · 0 comments
Closed

WSGI adaptor to serve RPC services #9

kanghyojun opened this issue Jul 26, 2016 · 0 comments
Assignees

Comments

@kanghyojun
Copy link
Member

kanghyojun commented Jul 26, 2016

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),
);
@kanghyojun kanghyojun added this to the Prepare to be public milestone Jul 26, 2016
@kanghyojun kanghyojun self-assigned this Jul 26, 2016
@kanghyojun kanghyojun changed the title WSGI adaptor to server RPC services WSGI adaptor to serve RPC services Jul 26, 2016
kanghyojun added a commit that referenced this issue Aug 4, 2016
* Implement RPC runtime for python #9

- Implement Service, WsgiApp to create nirum rpc service
  - Add nirum.rpc.WsgiApp, nirum.rpc.Service
  - Return appropriate error message / success response
  - Support /ping/ by default
- Fix deserializers
  - deserialize by class not from given data
  - deserialize generic type(eg. typing.Sequence) as python type
  - deserialize primitive type

* Fix deserialize_tuple_type, reviews

* Divide rpc requirements into service_requires

* Parse datetime by using iso8601

* All name can have behind name

* Reveal behind name in error message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant