Spacetime::Docs::C_REFERENCE::CliAndHttpApi
CLI & HTTP REST API Reference
The spacetime-cr binary and Spacetime::HTTPClient provide direct access to SpacetimeDB's /v1 HTTP REST API,
environment diagnostics, and code generation.
Executive Summary & Key Topics
| Topic | Method / Anchor | Description |
|---|---|---|
| CLI Commands | .topic_01_cli_commands |
Command-line subcommands supported by bin/spacetime-cr. |
| Spacetime::HTTPClient Endpoints | .topic_02_http_client |
REST client wrappers for /v1/identity and /v1/database. |
Related Guides & Source References
- Spacetime::HTTPClient
- Spacetime::Doctor
Class methods
topic_01_cli_commands
CLI Commands: Command-line subcommands supported by bin/spacetime-cr.
Key Topics & Information
- spacetime-cr generate --schema <file.json> [--output <file.cr>] [--module <ModuleName>]: Generates typed Crystal bindings from a local schema file.
- spacetime-cr generate --host <url> --db <database> [--output <file.cr>]: Fetches schema from a live SpacetimeDB server and generates Crystal bindings.
- spacetime-cr schema --host <url> --db <database>: Downloads and prints the raw JSON schema for a database.
- spacetime-cr sql --host <url> --db <database> "<SQL>": Runs an HTTP /v1/database/:name/sql query and prints results.
- spacetime-cr doctor: Verifies Crystal toolchain, BSATN self-check, and optional local SpacetimeDB server reachability.
topic_02_http_client
Spacetime::HTTPClient Endpoints: REST client wrappers for /v1/identity and /v1/database.
Working Examples
require "spacetime"
http = Spacetime.http("http://localhost:3000", token: ENV["SPACETIME_TOKEN"]?) if http.ping ident = http.create_identity schema = http.fetch_schema("my_database") puts "Tables: #{schema.tables.map(&.name).join(", ")}" end