How routing works
When a request arrives at/users/42:
- Mizu checks registered routes for a match
- It finds
GET /users/{id}if you registered it - The matching handler runs with
id = "42"
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
| Method | Usage |
|---|---|
app.Get(path, handler) | Read resources |
app.Post(path, handler) | Create resources |
app.Put(path, handler) | Replace resources |
app.Patch(path, handler) | Update resources |
app.Delete(path, handler) | Remove resources |
app.Head(path, handler) | Like GET, headers only |
app.Connect(path, handler) | Establish tunnel |
app.Trace(path, handler) | Debugging |
app.Handle(method, path, handler) | Any method |
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().
c.QueryValues() to read multiple parameters at once.
Group related routes
Groups help you organize routes with a common prefix, such as all/api endpoints.
/api/status and /api/users.
Mount other handlers
You can use existinghttp.Handler objects with Mizu routes.
embed package.