Skip to content

Build a posts feature end to end

You ship one feature — posts — into the Publish story’s blog app: entity, service, PostsController, validation, Postgres, and an e2e test. No JWT, no GraphQL — that complexity lives in api and auth. Each page leaves you with code that compiles and a command you can run.

hello for the quick-start binary, apps/blog/ for the tutorial app, and a posts/ feature with HTTP only.

  • Directoryapps/blog/
    • Cargo.toml
    • Directorysrc/
      • main.rs
      • module.rs
    • Directorytests/
      • Directorye2e/
        • main.rs
  • Directorycrates/
    • Directoryfeatures/
      • Directorysrc/
        • Directoryposts/
          • entity.rs
          • service.rs
          • module.rs
          • mod.rs
          • Directoryhttp/
            • controller.rs
            • module.rs
            • mod.rs

Two curls against the running binary — no token:

Terminal window
$ curl -s -X POST http://localhost:3005/posts \
-H 'Content-Type: application/json' \
-d '{"title":"Hello","body":"World"}'
{"id":"018f…","title":"Hello","body":"World"}
$ curl -s http://localhost:3005/posts/018f…
{"id":"018f…","title":"Hello","body":"World"}

And a passing e2e suite:

Terminal window
$ nestrs run test e2e
PASS [ …] blog::e2e posts_round_trip

The tutorial assumes you’ve already followed Getting started — a workspace you scaffolded with nestrs new hello, the nestrs CLI installed, and nestrs run dev hello serving Hello World from crates/features/src/hello/. Page 1 adds apps/blog/ with nestrs new blog; everything after that happens in blog, not hello. If you cloned this repository to explore Publish, scaffold hello and blog in a separate workspace — they are not hosted here. Skim Fundamentals, Configuration, and HTTP so module, provider, and controller are familiar terms. docker is available for the Postgres step.

Rust 1.96+ is required. The database and testing pages need Postgres (nestrs run db up); earlier pages run without one.

  • Scaffold the app — the next step: add apps/blog/ with nestrs new blog.
  • Publish — the reference workspace this tutorial builds toward.
  • Getting started — the workspace setup this tutorial assumes.