Simple guides introducing Fabrica with hands-on examples.
by
layout: post title: “Meet the Generated Client” description: “How the CLI and Go library help you use your API the same way every time.” author: “Alex Lovell-Troy” —
Note (v0.4.0): This post predates hub/spoke API versioning and the flattened resource envelope. Some snippets may differ from current generator output.
APIs are easier to use when the client is predictable. You should not have to remember custom flags or one‑off scripts. Fabrica generates two clients that match your server: a CLI and a Go library. They share patterns and types, so your shell steps and your code read the same way.
The CLI is generated from pkg/codegen/templates/client/cmd.go.tmpl. Commands are grouped by resource: list, get, create, update, patch, delete. Output can be tables or JSON, which makes it simple to script with tools like jq. Version‑specific commands appear only when a resource supports them, so the CLI is always in sync with your API.
The Go client library comes from pkg/codegen/templates/client/client.go.tmpl. Method names are predictable and typed: Get<Device>, Create<Device>, Update<Device>, Patch<Device>, and status‑only methods like Update<Device>Status. The client handles headers, content types, and patch formats for you. When API version headers are used, the client sets them.
The CLI creates a typed client with client.NewClient and calls methods that mirror your resources. The methods issue HTTP requests to the server’s generated routes (pkg/codegen/templates/server/routes.go.tmpl) and unmarshal responses into your types from apis/<group>/<version>/.... Status operations go to /status endpoints to avoid spec conflicts.
When you enable spec versioning on a resource, the generator adds version helpers and subcommands. The Go client gets List<Resource>Versions, Get<Resource>Version, and Delete<Resource>Version, and the CLI nests them under <resource> versions .... These come from the same templates, so you do not maintain them by hand.
The generated client is opinionated. It follows the server’s routes and types exactly. That keeps things consistent, but it is not a generic HTTP tool. If you need custom flows or experiments, you can wrap the client in your own package.
fabrica init myapp
fabrica add resource Device
fabrica generate
go run ./cmd/client/ device create --spec '{"name":"dev-01","description":"demo"}' -o json
Prefer -o json when you need to script. Use the status methods when workers or controllers update state, so spec and status do not clash. If your API adds versioned endpoints, re‑generate so the client gains matching commands and types.
docs/guides/quickstart.mdexamples/01-basic-crud/