Build a posts feature end to end
From hello to a running apps/blog binary — HTTP CRUD behind the guards, validation, Postgres, and an e2e test, one runnable page at a time.
You ship one feature — posts — into the Publish story’s
blog app: entity, service, a PostsController behind the guards,
validation, Postgres, and an e2e test. Each page leaves you with code that
compiles and a command you can run.
Pages 1–7 build your blog. Pages 8 to 10 read the reference api, and
apply what it shows to blog. That is a deliberate switch, and worth knowing
before you reach it: blog’s Post
has an id, a title and a body — no tenant column, no relation — because a small
domain is what makes pages 2 to 7 short. Per-caller row filtering and an
auto-resolved GraphQL relation both need a domain that has those things, so
pages 8 and 10 walk through the feature that does (api’s users) rather than
first sending you to add a column you have no use for. Each leads back to your
own blog: page 9 narrows its policy, page 10 adds a GraphQL resolver to posts.
What you end up with
Section titled “What you end up with”hello for the quick-start binary, apps/blog/ for the tutorial app, a
posts/ feature over HTTP and then GraphQL, its table’s migration, and the
auth adapter nestrs g resource writes with it on page 2 — a DB-backed route
is guarded from its first request.
Directoryapps/blog/
- .env the port
- Cargo.toml
Directorysrc/
- main.rs
- module.rs
Directorytests/
Directorye2e/
- main.rs
- posts.rs
Directorycrates/
Directoryfeatures/
Directorysrc/
Directoryauthn/
- …
Directoryauthz/
- …
Directoryposts/
- entity.rs
- service.rs
- module.rs
- mod.rs
Directorygraphql/
- resolver.rs
- module.rs
- mod.rs
Directoryhttp/
- controller.rs
- module.rs
- mod.rs
Directorymigrations/
Directorysrc/
- m20260609_000000_create_posts.rs
Two curls against the running binary, carrying the development token
POST /auth/dev-token mints on
Persist through Postgres. The bearer is not optional:
Repo filters every read by the caller’s ability, so the guards go on with
the database, not later.
$ curl -s -X POST http://localhost:3001/posts -H "Authorization: Bearer $TOKEN" \ -H 'Content-Type: application/json' \ -d '{"title":"Hello","body":"World"}'{"id":"018f…","title":"Hello","body":"World","created_at":"2026-…","updated_at":"2026-…"}
$ curl -s http://localhost:3001/posts/018f… -H "Authorization: Bearer $TOKEN"{"id":"018f…","title":"Hello","body":"World","created_at":"2026-…","updated_at":"2026-…"}And a passing e2e suite:
$ nestrs run test e2e PASS [ …] blog::e2e posts::posts_round_tripWhat you should know going in
Section titled “What you should know going in”- A workspace scaffolded per Getting started —
the
nestrsCLI installed andnestrs run dev helloservingHello Worldfromcrates/features/src/hello/. - Rust 1.100+, and enough of Fundamentals, Configuration, and HTTP that module, provider, and controller are familiar terms.
- Docker available — the database and testing pages need Postgres
(
docker compose up -d, the servicesnestrs newscaffolded); earlier pages run without one. - Page 1 adds
apps/blog/withnestrs new blog; everything after that happens inblog, nothello, and every command runs from the workspace root.
The pages, in order
Section titled “The pages, in order”Going further
Section titled “Going further”- Scaffold the app — the next step: add
apps/blog/withnestrs new blog. - Publish — the reference workspace this tutorial builds toward.
- Getting started — the workspace setup this tutorial assumes.