Skip to main content
Routing determines which handler runs for each incoming request. It matches the request’s URL path and HTTP method to your registered routes.

How routing works

When a request arrives at /users/42:
  1. Mizu checks registered routes for a match
  2. It finds GET /users/{id} if you registered it
  3. The matching handler runs with id = "42"
Mizu uses Go 1.22’s ServeMux internally, which means you get the same routing patterns from the standard library with cleaner syntax.

Defining routes

Each route has three parts: an HTTP method, a path, and a handler.

Available methods

Use path parameters

You can capture variable parts of a URL using braces {}.
For example, /users/{id} matches /users/42.

Handle query strings

When a URL includes a query string such as /search?q=go, you can read it with c.Query().
You can also use c.QueryValues() to read multiple parameters at once. Groups help you organize routes with a common prefix, such as all /api endpoints.
This example creates /api/status and /api/users.

Mount other handlers

You can use existing http.Handler objects with Mizu routes.
You can also serve static files.
Or serve embedded files using Go’s embed package.

Customize not found behavior

If no route matches, Mizu uses a default 404 page. You can replace it with your own handler.

Handle errors globally

You can define a global error handler to catch returned errors or panics.
This makes error handling consistent for all routes.

Next steps

Handler

Write request handling logic.

Context

Access request data and send responses.