Skip to main content
In this tutorial, you will extend the quickstart server into a small in-memory message API. The application demonstrates route registration, parsed request data, typed path parameters, validation, and JSON responses without introducing a database.
Begin with the working server from Quickstart. The in-memory messages in this tutorial are discarded whenever the process stops.

Define application state

In bin/server.dart, add a list after resolving the router:

List messages

Register a collection route:
Start the server and test it:

Read a typed route parameter

Archery validates and coerces {id:int} before the handler runs. Retrieve the typed value through RouteParams:
Try an existing message:

Parse and validate input

request.form() supports JSON, URL-encoded, and multipart request bodies. Add a route that accepts a message value:
Create a message with URL-encoded data:
Or send JSON:

Verify invalid input

The handler returns status 422 and a JSON error. This validation is intentionally local to the tutorial; reusable request validation belongs in a dedicated form-request layer.

What you used

  • Router.get() and Router.post() to register HTTP methods
  • {id:int} and RouteParams.get<int>() for typed path data
  • request.form() for cached request parsing
  • request.json() for consistent JSON responses
  • HttpStatus values to communicate creation, validation failure, and missing records

Routing

Learn route groups, matching priority, and middleware.

Requests

Work with forms, JSON, files, and response helpers.