Skip to main content
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 like /, /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 named main.go and add this code:

Run

Open your terminal and run:
Then open your browser and visit:

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.

Try something new

Add a route that returns a custom status code or HTML content. For example:
Register it like this:
Then visit http://localhost:8080/404 to test it. Routing is the core of every Mizu app. Once you are comfortable defining routes and handlers, you are ready to build full pages and APIs. Next, continue to JSON Responses to learn how to send structured data from your routes.