Introduction
hyrule is a Go framework for scaffolding microservices fast, and testing their flows just as fast. You describe a resource — its fields, its validation rules, which HTTP methods it answers to — and get a working REST API for it. What that buys you, specifically:
- Full CRUD, validation and pagination from a schema, with no hand-written handler.
- Optimistic concurrency built in — ETags and
If-Match, not something you wire up yourself. - Mongo or Postgres, same HTTP contract — a resource with its own
Go code picks either backend through
rest.Adapterfor CRUD, validation, ETags and querying; see the Adapter reference page. - A transactional outbox: a write and the event it causes commit together, in the same transaction, or neither does. No separate job that can drift from what actually got written.
- Dry run: a whole service runs against real traffic with every write rolled back — so you exercise actual flows, including ones that span several writes and an outbox event, without faking any of it.
testkit: an isolated database and an HTTP client per test, no service to stand up, no mocks of your own storage.
Mongo and Postgres both support the Go bootstrap, transactional outbox and dry run. YAML/scaffolding and testkit's database provisioner remain Mongo-specific; Postgres uses Go registration and a real isolated pool with the shared HTTP helpers. Start with Integrating Mongo and Postgres for equally detailed setup, runnable programs and test guidance for either.
You can describe that resource two ways. In Go:
res := &rest.Resource{
Name: "tags",
Store: env.Store("tags"),
Schema: rest.Schema{
"name": {Type: rest.TypeString, Required: true},
"slug": {Type: rest.TypeString, Required: true, Unique: true},
},
}
env.API.Register(res)
Or, for the common case, in a YAML file — no Go at all:
resources:
- name: tags
collection: tags
schema:
name: {type: string, required: true}
slug: {type: string, required: true, unique: true}
RESOURCES_FILE=resources.yaml go run ./cmd/hyrule-serve
Both register the same kind of resource, through the same Resource
type underneath. That's the whole idea: start from data, drop into Go
only for the parts that genuinely need code.
- What a
Resourceactually is, and whatStoredecouples it from - How to add relations between resources, and how hooks run on a write
- How the transactional outbox lets a write and its side effects commit together — and how to make an event fire because of a write, not because some endpoint remembered to send it
- How to test a resource without standing up a whole service
- When a resource is better left as Go instead of YAML
The running example
This guide builds toward blog-apis, the small example that ships
with the framework: authors-api and tags-api are plain CRUD,
categories-api is a hierarchy, and posts-api ties them together with
relations, hooks, and an outbox-driven publish flow. comments-api demonstrates
Postgres with the same bootstrap and transactional Pub/Sub publishing. Every snippet in
this guide is real code from that example or from the framework
itself — nothing here is invented for the docs.
If you'd rather read the example directly, it's at
examples/blog-apis
in the repository. If you'd rather be guided through it one concept at a
time, keep reading — start with Quick Start.
- hyrule turns a resource description into a full CRUD API.
- A resource can be written in Go or in YAML; both paths are first-class.
- This guide uses blog-apis as one running example, building it up concept by concept.