DualAPI
A lightweight and extensible framework for distributed isomorphic javascript applications. DualAPI extends dual-protocol, adding convenience functions and default behaviors for common messaging patterns.
For a simple example distributed example, see the dual-engine.io example.
Constructing domains
The dualapi
module is the constructor for dualapi
domains.
var d = ;
The most common use case for dualapi
domains is to provide
a listener function for processing dual-protocol
messages. Hosts
are attached to the domain by using the
dual-protocol mount
method:
d;
Request and Return
Often, a dualapi
host will emit a response after processing
input. dualapi
provides a convienent extension to dual-protocol
by providing the ctxt.return
method.
d;
By default, return
sets the returned options.statusCode
to 200
.
Then, any method having access to a connected domain may request data
from this address. The
request
method returns a spreadable promise which will be resolved when the
source host replies:
d ; // prints: // "200 the processed response"
A smarter database can override the response statusCode
by providing
explicit options.
var db = {}; d; d;
A client can use the enhanced status codes to modify its own response:
d ; d ; d ; // Running this the first time would print: // 404 Failed to retrieve from bucket // 201 Wrote to bucket // 200 Second request got: an egg // Running a second time would print: // 200 Request returned: an egg // 409 Failed to write to bucket. // 200 Second request got: an egg
On the other hand, if no host is listening at the requested address,
request will return with a status code of 503
. The request may also
provide a timeout option, in which case the status code will be 504
.
d ; // would print// "nowhere" request returned status code 503 d ; // would print (after 1 second delay)// "unresponsive" request returned status code 504
Forward
To be written.
Proxy
To be written.
Error
To be written.