A practical, ops‑friendly quick start: what you’ll build, how spec/status works, and four commands to get an API running.
You often need a small, reliable inventory API long before you need a full CMDB. You want CRUD, a stable schema, OpenAPI, and a storage backend you can swap later. Fabrica gives you that in minutes. It’s a code generator for Go that emits production‑ready HTTP handlers, storage, and OpenAPI. It also follows OpenCHAMI’s resource envelope, so services like SMD or Magellan can consume your data without glue code.
This post walks through a simple “Device” inventory API. You’ll see how the spec/status model works, why it helps operations, and how to get something running with four commands. No framework spelunking. No scaffolding clean‑up.
You’ll create a tiny service called inventory‑api that:
Fabrica uses a Kubernetes‑style split between desired state (spec) and observed state (status):
By keeping spec empty for Device, you signal that inventory is observational. Day‑2 tools can safely update status without worrying about intent. Your UIs and reports get a consistent shape, and you stay aligned with other OpenCHAMI services.
Each Device is wrapped in common metadata (name, uid, labels, createdAt/updatedAt). The spec is empty. The status holds facts your scanners discover: deviceType, manufacturer, partNumber, serialNumber, parent relationships, and a free‑form properties map. Keep properties small and documented; promote stable fields to first‑class keys over time.
Pre‑reqs you likely already have
This gets you a local API listening on 8080. Replace names to taste.
fabrica init inventory-api && cd inventory-api
fabrica add resource Device
fabrica generate
go run ./cmd/serverOpen http://localhost:8080/swagger to explore endpoints and try requests in the browser. You’ll see standard CRUD routes for /devices. Create a resource by name; the server assigns a UID. Update status with facts discovered by your scanners. Retrieve devices with filters to drive reports.
For a Device resource, keep spec empty and put facts in status:
Start with the minimal set you need today. Add fields as operational needs harden. Fabrica regenerates handlers and OpenAPI when you evolve the structs.
Because the resource envelope matches OpenCHAMI conventions, you can:
From the Swagger UI, POST a Device with a name and labels, then PUT its status with discovered facts. GET it back and confirm the envelope and fields look right. Use browser‑based tools here to keep this guide within four commands.
Ready to try OpenCHAMI?