Skip to main content
In this tutorial, you’ll create a simple web application that responds to HTTP requests. We’ll go step by step, explaining each concept as we encounter it. By the end, you’ll understand how web servers work and the core concepts of Mizu.

Prerequisites

Before starting, make sure you have:
  • Go installed (version 1.22 or later)
  • Mizu CLI installed
  • A text editor
Not sure? Run these commands:

Step 1: Create the Project

Open your terminal and run:
You should see:

Step 2: Enter the Project

Look at what was created:
Output:

Step 3: Install Dependencies

This downloads the Mizu framework and updates go.mod with the correct version.

Step 4: Run the Server

Output:
Your server is running!

Step 5: Test It

Open another terminal (keep the server running) and test with curl:
Output:
Or open http://localhost:8080 in your browser.

Step 6: Stop the Server

Go back to the terminal running mizu dev and press Ctrl+C:

Understanding the Code

Now let’s look at the code. Open main.go in your editor:

Key Concepts

1. Creating the App
This creates a new Mizu application instance. It sets up the HTTP router and prepares everything for handling requests. 2. Adding a Route
  • app.Get means “handle GET requests”
  • "/" is the path (root URL)
  • The function is your handler - it runs when someone visits /
  • c is the context - it has request info and response methods
  • c.Text(200, ...) sends a plain text response with status code 200
3. Starting the Server
This starts the HTTP server on port 8080 and waits for requests.

Exercise 1: Add a New Route

Let’s add an /about page. Edit main.go:
Restart the server:
Test the new route:
Output:

Exercise 2: Return JSON

APIs usually return JSON. Let’s add a JSON endpoint. Edit main.go:
Restart and test:
Output:

Exercise 3: URL Parameters

Let’s create a route that uses URL parameters. Edit main.go:
Restart and test:
Output:
The :name in the route is a parameter. Whatever value is in that position gets captured and is available via c.Param("name").

Exercise 4: Query Parameters

Query parameters are the ?key=value part of URLs. Edit main.go:
Restart and test:
Output:

What You’ve Learned

In this tutorial, you learned:
  1. Create a project with mizu new
  2. Run a server with mizu dev
  3. Add routes with app.Get()
  4. Return text with c.Text()
  5. Return JSON with c.JSON()
  6. Use URL parameters with :name and c.Param()
  7. Use query parameters with c.Query()

Next Steps

You’ve mastered the basics. Here are some options:

API Template

Learn a production-ready project structure

Middleware

Add logging, auth, and more to your routes

Context Deep Dive

Learn all the context methods

Examples

See more complete examples