runService()
function runService(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
collectionmust be the name of one of the service's input collections, that is, one of the keys of theInputstype 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 namedcollectionwith 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/jsonheader. The body of the request must be a JSON-encoded value, which will be passed as parameters to the resource constructor. Instantiates the namedresourcewith 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. -
GET /healthzCheck that the Skip service is running normally. Returns HTTP 200 if the service is healthy, for use in monitoring, deployments, and the like.
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-streamheader. Theuuidmust have been obtained from aPOST /v1/streamsrequest, and not yetDELETEd. Provides an HTTP server-sent event stream of updates to the resource identified byuuid. Each event will be a serialization of aCollectionUpdateof the form:
event: (init | update)\n
id: <watermark>\n
data: <values>\n\n
GET /healthzCheck that the Skip service is running normally. Returns HTTP 200 if the service is healthy, for use in monitoring, deployments, and the like.
Parameters
| Parameter | Type | Description |
|---|---|---|
service | SkipService | The SkipService definition to run. |
options | { control_port: number; no_cors: boolean; platform: "native" | "wasm"; streaming_port: number; } | Service configuration options. |
options.control_port | number | Port on which control service will listen. |
options.no_cors? | boolean | Disable CORS for the streaming endpoint. |
options.platform? | "native" | "wasm" | Skip runtime platform to be used to run the service: either wasm (the default) or native. |
options.streaming_port | number | Port on which streaming service will listen. |
Returns
Promise<SkipServer>
Object to manage the running server.