runService()
function runService<Inputs, ResourceInputs>(service, options): Promise<SkipServer>
Initialize and start a reactive Skip service.
Calling runService
will start a reactive service based on the service
specification and options
.
The service offers two interfaces over HTTP: a control API on options.control_port
, and a streaming API on options.streaming_port
.
The service exposes resources and input collections specified by service: SkipService
.
Resources can be read and input collections can be written.
Each input collection has a name, and associates keys to values.
Each resource has a name and identifies a collection that associates keys to values.
The control API responds to the following HTTP requests:
POST /v1/snapshot/:resource
: Synchronous read of an entire resource.
The body of the request must be a JSON-encoded value, which is passed as parameters to the resource constructor.
Responds with the current contents of the named resource
with the given parameters, instantiating the resource if needed.
Data is returned as a JSON-encoded array of key/value entries, with each entry a tuple of the form [key, [value1, value2, ...]]
.
POST /v1/snapshot/:resource/lookup
: Synchronous read of a specific key in a resource.
The body of the request must be a JSON-encoded object with a key
field and a params
field.
Responds with the values associated to key
in the named resource
with the given parameters, instantiating the resource if needed.
Data is returned as a JSON-encoded array of values.
-
PATCH /v1/inputs/:collection
: Partial write (update only the specified keys) of an input collection.The
collection
must be the name of one of the service's input collections, that is, one of the keys of theInputs
type parameter. The body of the request must be a JSON-encoded value of typeCollectionUpdate.values
, that is[Json, Json[]][]
: an array of entries each of which associates a key to an array of its new values. Updates the namedcollection
with the key-values entries in the request body. -
POST /v1/streams/:resource
: Instantiate a resource and return a UUID to subscribe to updates.Requires the request to have a
Content-Type: application/json
header. The body of the request must be a JSON-encoded value, which will be passed as parameters to the resource constructor. Instantiates the namedresource
with the given parameters and responds with a UUID that can be used to subscribe to updates. -
DELETE /v1/streams/:uuid
: Destroy a resource instance.Destroys the resource instance identified by
uuid
. Under normal circumstances, resource instances are deleted automatically after some period of inactivity; this interface enables immediately deleting live streams under exceptional circumstances.
The streaming API responds to the following HTTP requests:
-
GET /v1/streams/:uuid
: Server-sent events endpoint to subscribe to updates of the resource instance represented by the UUID.Requires the request to have an
Accept: text/event-stream
header. Theuuid
must have been obtained from aPOST /v1/streams
request, and not yetDELETE
d. Provides an HTTP server-sent event stream of updates to the resource identified byuuid
. Each event will be a serialization of aCollectionUpdate
of the form:
event: (init | update)\n
id: <watermark>\n
data: <values>\n\n
Type Parameters
Type Parameter | Description |
---|---|
Inputs extends NamedCollections | Named collections from which the service computes. |
ResourceInputs extends NamedCollections | Named collections provided to resource computations. |
Parameters
Parameter | Type | Description |
---|---|---|
service | SkipService <Inputs , ResourceInputs > | Service specification. |
options | { control_port : number ; streaming_port : number ; } | Service configuration options. |
options.control_port | number | Port on which control service will listen. |
options.streaming_port | number | Port on which streaming service will listen. |
Returns
Promise
<SkipServer
>
Object to manage the running server.