In this lesson, you will learn how routing works in Mizu. Routing controls what happens when someone visits a specific URL. You can define routes for different paths likeDocumentation Index
Fetch the complete documentation index at: https://docs.go-mizu.dev/llms.txt
Use this file to discover all available pages before exploring further.
/, /about, or /api, and Mizu will call the right handler function automatically.
Each route uses a plain Go function that takes a *mizu.Ctx and returns an error. This keeps your code simple and easy to follow.
Code
Create a file namedmain.go and add this code:
Run
Open your terminal and run:- http://localhost:8080/ Shows “Welcome to Mizu!”
- http://localhost:8080/about Shows “This is the About page.”
- http://localhost:8080/hello/Alice Shows “Hello, Alice”
- http://localhost:8080/api/time Shows the current time in JSON format.
How it works
Each route is matched to a specific function. For example,/hello/{name} includes a placeholder, and Mizu automatically extracts the value so you can read it with c.Param("name").
When a request matches a path, Mizu runs the correct handler. Inside your function, you can use c.Text() to send text or c.JSON() to return structured data. Every handler returns an error so you can add custom error handling later if needed.