Skip to content

Persistance layer

For convenience, pmesh exposes a simple REST API for interacting with the persistence layer. Allowing you to interact with the key-value store, publish events and requests, and retrieve the results of operations.

Get Key GET /kv/:key

Retrieves the state of a specific key within the session’s key-value store.

The result is an object with the following structure:

ResultTypeDescription
revisionuint64The revision number of the key.
valueanyThe value associated with the key.
Terminal window
$ curl http://pm3/kv/exampleKey
{
"revision": 42,
"value": 4
}

Set Key | PUT /kv/:key

Sets or updates the value of a specific key. If revision is specified, the update will be conditional on matching the provided revision.

The result is the new revision number of the key.

Terminal window
$ curl -X PUT http://pm3/kv/exampleKey -d '{"revision":42, "value": 4}'
42

Delete Key | DELETE /kv/:key

Deletes a specific key from the key-value store.

Terminal window
$ curl -X DELETE http://pm3/kv/exampleKey

List Keys | GET /kv

Retrieves a list of all keys in the key-value store.

The result is an array of key names.

Terminal window
$ curl http://pm3/kv
["exampleKey1", "exampleKey2", ...]

Atomic Swap | /kv/:key/cas

Performs an atomic compare-and-swap operation on a specific key. The operation will succeed if the current value matches the expected value, updating it to the desired value.

The result is an object with the following structure:

ResultTypeDescription
okboolWhether the operation succeeded.
diffanyThe difference between expected and actual value in JSON-diff format, if the operation failed.
revisionuint64The new revision number of the key, if the operation succeeded.
valueanyThe new value of the key, if the operation succeeded.
Terminal window
$ curl -X POST http://pm3/kv/exampleKey/cas -d '{"expected": 4, "desired": 5}'
{
"ok": true,
"diff": "",
"revision": 43,
"value": 5
}

Publish Request | /publish/:topic

Publishes an NATS request to a specific topic. The body is the raw event payload and the result is the response from the subscription.

Terminal window
$ curl -X POST http://pm3/publish/greet.people -d '{"name": "world"}'
{"stream":"ev", "seq":5189}

Retrieve Result | /result/:stream/:seq

Fetches the result of a specific operation identified by a stream and sequence number.

The result is the value associated with the operation.

Terminal window
$ curl http://pm3/result/exampleStream/42
{"operationResult":"success"}