-
Notifications
You must be signed in to change notification settings - Fork 8
feature: make arri transport agnostic #181
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
Draft
joshmossas
wants to merge
175
commits into
master
Choose a base branch
from
feature/transport-spec-experiments
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ure/transport-spec-experiments
…ure/transport-spec-experiments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces the concept of "TransportAdapters" and "TransportDispatchers".
TransportAdapter- Exists on the server. They adapt requests and messages coming from a transport such as websockets or http and transform them into a generic arri request.TransportDispatcher- Exists on the client. They take in a generic arri request and transform them into a payload specific to the chosen transport.With this change Arri essentially becomes a generic "Request > Response" system that can be adapted to any transport through use of these TransportAdapters and TransportDispatchers. This also means that Arri itself is no longer concerned with establishing or maintaining active connections this is all handled at the Adapter and Dispatcher layer.
Arri servers can have multiple TransportAdapters installed, and Arri clients can have multiple TransportDispatchers installed. Additionally transports can be enabled globally or at a "per-procedure" level. So for example you can have all procedures default to
httpand then enabledwsfor specific procedures or vice versa.Lastly this PR will ship with 1st party integrations for
httpandwebsockets. Documentation will be added in the future for people who want to make their own integrations to support custom transports such astcpudpetc.Examples
All examples are in Typescript, but the same concepts will apply to other languages.
Registering a TransportAdapter
Register Multiple TransportAdapters
Client Usage
The Arri clients will autoinstall the HTTP and Websocket adapters depending on which transports are available by the server
For custom transports you will have to manually install them when initializing the client.
Arri Messages
In order to enable this I've also created a generic Arri message format that can be encoded and decoded by Arri clients and servers. This allows developers to use the same exact encode/decode functions regardless of the transport being used. The only exception is when procedures sent over HTTP. In those cases Arri messages get converted to HTTP requests and responses.
Client Messages
ARRIRPC/0.0.8 sayHello req-id: 1 content-type: application/json {"name":"john doe"}ARRIRPC/0.0.8 sayGoodbye req-id: 2 content-type: application/json some-custom-header: foo {"name":"john doe"}Server Messages
ARRIRPC/0.0.8 SUCCESS req-id: 1 content-type: application/json {"name":"hello john"}ARRIRPC/0.0.8 FAILURE req-id: 1 content-type: application/json {"code":400,"message":"Invalid parameter [/name]. Expected string."}Server Event Stream Messages
Start of an "event stream"
Received new event
ARRIRPC/0.0.8 ES_EVENT req-id: 1 event-id: 15 {"message":"hello world"}Event stream has event
Some notes
\n\n\nreq-idis only unique to the client. it is used by the client to track which responses belong to which requestsapplication/jsonis the only supported content type at this time. Eventually we will add support for some kind of binary format (mostly likely CBOR or Messagepack)List of reserved header keys:
app.info.versionoption. you can use this to see what api version you client was generated withAny other header names will be considered as "custom headers". For example you can use a custom "authorization" header to pass an auth token similar to how you would in a standard HTTP api.