Spacetimedbex.Http (spacetimedbex v0.1.2)

Copy Markdown View Source

HTTP client for the SpacetimeDB REST API (v1).

All functions take host (e.g. "localhost:3000") as the first argument and return {:ok, result} | {:error, reason} tuples. Authentication is handled via explicit token parameters — no global state.

Uses Req for HTTP, consistent with Spacetimedbex.Schema.fetch/2.

Summary

Functions

Create a new identity and token.

Get database metadata.

Get database identity hex string.

List all names for a database.

List databases owned by identity.

Get the public key for verifying tokens (PEM format).

Get a short-lived websocket token.

Ping the server. Returns :ok on success.

Fetch database schema. Delegates to Spacetimedbex.Schema.fetch/2.

Replace the full name list for a database.

Execute one or more SQL queries against a database.

Verify that token belongs to identity. Returns :ok on 204.

Functions

add_database_name(host, name_or_identity, new_name, token)

Add a name to a database.

call_reducer(host, database, reducer_name, args, token)

Call a reducer on a database.

create_identity(host)

Create a new identity and token.

delete_database(host, name_or_identity, token)

Delete a database.

get_database(host, name_or_identity)

Get database metadata.

get_database_identity(host, name_or_identity)

Get database identity hex string.

get_database_names(host, name_or_identity)

List all names for a database.

get_databases(host, identity)

List databases owned by identity.

get_public_key(host)

Get the public key for verifying tokens (PEM format).

get_websocket_token(host, token)

Get a short-lived websocket token.

logs(host, database, token, opts \\ [])

Fetch database logs.

Options:

  • :num_lines - number of log lines (integer)
  • :follow - stream logs (boolean, not yet supported — returns single response)

ping(host)

Ping the server. Returns :ok on success.

publish_database(host, name_or_identity, wasm_binary, token, opts \\ [])

Publish a WASM module to a database.

Options:

  • :clear - clear existing data on update (boolean)

schema(host, database)

Fetch database schema. Delegates to Spacetimedbex.Schema.fetch/2.

set_database_names(host, name_or_identity, names, token)

Replace the full name list for a database.

sql(host, database, query, token)

Execute one or more SQL queries against a database.

Returns {:ok, results} where results is a list of %{schema: schema, rows: rows} maps, one per statement.

verify_identity(host, identity, token)

Verify that token belongs to identity. Returns :ok on 204.