Skip to content

feat(api): add raw Firestore REST API subcommand#56

Merged
gugahoi merged 1 commit into
mainfrom
feat/api-command
Jun 25, 2026
Merged

feat(api): add raw Firestore REST API subcommand#56
gugahoi merged 1 commit into
mainfrom
feat/api-command

Conversation

@gugahoi

@gugahoi gugahoi commented Jun 25, 2026

Copy link
Copy Markdown
Owner

What

Adds firestore api <path> — a gh api-style escape hatch for hitting any Firestore REST endpoint with the project and credentials already configured. Covers interactions the CLI does not wrap yet (named databases, :runQuery, :batchGet, field masks, admin endpoints, ...) without needing a bespoke command for each.

Behaviour

  • Path resolution: relative paths (users/u1) expand under projects/<project>/databases/(default)/documents/; paths starting with projects/ are sent verbatim (after /v1/) for admin/query endpoints.
  • Placeholders: {project}--project/PROJECT_ID, {database}(default).
  • Flags: -X/--method (default GET, or POST when a body is given); --input <file> or --input - (STDIN), with automatic application/json content-type.
  • Auth: Application Default Credentials (firestore auth login); uses the emulator with no real creds when --host/FIRESTORE_EMULATOR_HOST is set.
  • Output: pretty-printed JSON (raw fallback); HTTP >= 400 returns a non-zero exit with the error body.
  • Full behaviour documented in firestore api --help.

No new dependencies — golang.org/x/oauth2/google was already available.

Testing

  • go build, go vet ./..., go test ./... all green; unit tests cover path resolution (relative/verbatim/placeholders/leading-slash) and method defaulting.
  • End-to-end against the Firestore emulator: create (POST via STDIN), get, :runQuery with placeholders, delete, and a 404 returning a non-zero exit with the error body — all verified.

Adds `firestore api <path>`, a gh-api-style escape hatch for Firestore
operations the CLI does not wrap yet (named databases, :runQuery, admin
endpoints, etc.). Relative paths expand under the project's documents
collection; paths starting with `projects/` are sent verbatim. Supports
{project}/{database} placeholders, -X/--method, and --input (file or STDIN).
Auth reuses ADC; falls back to the emulator when --host is set.
@gugahoi
gugahoi merged commit b1aaab1 into main Jun 25, 2026
2 checks passed
@gugahoi
gugahoi deleted the feat/api-command branch June 25, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant