romm-api
Shared HTTP client, API types, configuration, and domain logic for RomM frontends (CLI, TUI, and future Android via UniFFI).
Crate path: romm-api/ in the workspace.
When to use this crate
| Use case | Dependency |
|---|---|
| New embedders, Android prep, minimal deps | romm-api directly |
| Existing library consumers on crates.io | romm-cli (re-exports romm_api) |
[]
= "0.40"
= { = "1", = ["macros", "rt-multi-thread"] }
Quick start
use RommClient;
use load_config;
use RommError;
async
Run cargo doc -p romm-api --open for the full API reference.
Module overview
| Module | Purpose |
|---|---|
client |
RommClient — typed HTTP calls, downloads, uploads |
endpoints |
One type per API route (Endpoint trait) |
types |
Shared serde models |
config |
load_config, auth, paths, keyring integration |
error |
ApiError, ConfigError, DownloadError, RommError, exit codes |
core |
Cache, downloads, library scan helpers, resolve utilities |
openapi |
OpenAPI fetch/cache and endpoint lookup |
feature_compat |
Server capability checks from OpenAPI |
update |
Self-update helpers (used by CLI/TUI binaries) |
See HTTP client and endpoints for request/response patterns and streaming downloads.
Configuration
All frontends share the same configuration layer in romm-api::config.
Setup wizard (CLI)
The easiest way to create config.json is through the CLI:
Config file location
config.json lives under the OS config directory (for example ~/.config/romm-cli/config.json on Unix, or %APPDATA%\romm-cli\config.json on Windows).
API_BASE_URL should match the RomM website address from your browser (scheme, host, port only), for example https://romm.example.com or http://my-server:1738.
The library does not auto-load a .env file. Set environment variables in your shell or process manager.
Auth problems (keyring, Docker, CI, Windows credentials): see troubleshooting-auth.md.
API token (recommended)
Prefer --token-file over --token to keep secrets out of shell history. The CLI stores the token in the OS keyring when available.
Non-interactive init flags:
--url <URL>— RomM origin (browser-style).--token <TOKEN>— Bearer token string.--token-file <PATH>— Read token from UTF-8 file. Use-for stdin.--download-dir <PATH>— Override the default ROMs directory.--no-https— Disable HTTPS (use HTTP instead).--check— Verify URL and token after saving.--force— Overwrite existing configuration without asking.--print-path— Print the path toconfig.jsonand exit.
Environment variables
| Variable | Description |
|---|---|
API_BASE_URL |
RomM site URL (browser address, no /api) |
ROMM_ROMS_DIR |
Base directory for stored ROMs (preferred) |
ROMM_DOWNLOAD_DIR |
Legacy alias for ROMM_ROMS_DIR |
API_USE_HTTPS |
Set to false to disable automatic upgrade to HTTPS |
API_USERNAME / API_PASSWORD |
Basic Auth credentials |
API_TOKEN |
Bearer token |
ROMM_TOKEN_FILE |
Path to bearer token file (alias: API_TOKEN_FILE). Max 64 KiB. |
API_KEY_HEADER / API_KEY |
Custom API key header and value |
ROMM_CACHE_PATH |
Override ROM list cache path |
ROMM_LIBRARY_METADATA_SNAPSHOT_PATH |
Override TUI library metadata snapshot path |
ROMM_OPENAPI_BASE_URL |
OpenAPI origin if different from API_BASE_URL |
ROMM_OPENAPI_PATH |
Override downloaded OpenAPI cache path |
ROMM_USER_AGENT |
Override HTTP User-Agent |
ROMM_VERBOSE |
Verbose HTTP logging (1/true) |
ROMM_CHECK_UPDATES |
Set to false/0/no/off to disable update checks |
ROMM_THEME |
TUI color theme ID (see TUI documentation) |
ROMM_GITHUB_API_BASE |
Override GitHub API base for self-update |
ROMM_GITHUB_RELEASES_API |
Override GitHub releases list URL (component tag filtering) |
ROMM_GITHUB_LATEST_RELEASE_API |
Legacy override; redirects to releases list when it points at /releases/latest |
Test-only variables (ROMM_TEST_*) are omitted. For auth precedence and keyring behavior, see troubleshooting-auth.md.
Configuration precedence
Settings merge per field from lowest to highest precedence:
- Built-in defaults — HTTPS enabled, default theme, OS download folder.
config.json— written byromm-cli init, TUI setup, Settings, orauth login.- Environment variables — override
config.jsonfor matching fields. - OS keyring — resolves
<stored-in-keyring>placeholders after env + file merge. - Command-specific CLI runtime — only where documented (e.g.
download --output).
Examples:
config.jsonhasbase_urlhttps://romm.local, butAPI_BASE_URL=https://romm.prodis set →https://romm.prodis used.romm-cli download --output /tmp/romsuses/tmp/romsfor that run.
There are no global --url / --token flags on normal commands. Connection settings come from env + file + keyring.
Custom console paths
Default download layout: {base Roms Dir}/{platform-slug}/.
Map individual consoles in config.json or via TUI Settings → ROMs → Console paths:
Keys in platform_dirs are RomM platform IDs. Unmapped consoles use the base subfolder.
Custom console save paths
Default save layout: {Save Dir}/{platform-slug}/{game}/.
Map consoles in Settings → Saves → Save console paths or config.json:
Errors and exit codes
Library methods return typed errors from romm_api::error. The CLI binary maps them to process exit codes via romm_api::exit:
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | General failure |
| 2 | Usage error (invalid flags) |
| 3 | Config / auth |
| 4 | API / network / download |
See CLI documentation for scripting examples.
Workspace utilities
| Binary | Crate | Purpose |
|---|---|---|
romm-openapi-gen |
romm-api |
Regenerate OpenAPI-derived helpers |