Skip to main content
Let’s start with your first Mizu app. You will build a small web server that shows Hello, Mizu in your browser. It is a simple way to see how Mizu works while keeping everything clear and easy to follow. Mizu uses Go’s standard library under the hood, so if you have seen net/http before, this will look familiar.

Code

Create a file called main.go and add this code:
package main

import (
	"log"
	"net/http"

	"github.com/go-mizu/mizu"
)

// home handles requests to the root path ("/")
func home(c *mizu.Ctx) error {
	return c.Text(http.StatusOK, "Hello, Mizu")
}

func main() {
	app := mizu.New()

	// Register the route
	app.Get("/", home)

	// Start the server
	if err := app.Listen(":8080"); err != nil {
		log.Fatal(err)
	}
}
Here is what happens step by step:
  • mizu.New() creates your web app.
  • app.Get("/", home) connects the URL / to your home handler.
  • home() sends a plain text message with status code 200 OK.
  • app.Listen(":8080") runs the server and waits for requests.

Run

Open your terminal and run:
go run .
You will see:
Listening on :8080
Then open http://localhost:8080 in your browser. You should see Hello, Mizu on the screen.

How it works

When you visit /, Mizu matches that route and calls the home function. Inside home, the line c.Text(http.StatusOK, "Hello, Mizu") sends a text response back to the browser with a 200 OK status. This is the basic flow in every Mizu app: receive a request, handle it with a function, and send a response using the context c.

Try something new

You can change the message to anything you like:
func home(c *mizu.Ctx) error {
	return c.Text(http.StatusOK, "Hello, Go!")
}
Or add another route:
func about(c *mizu.Ctx) error {
	return c.Text(http.StatusOK, "This is the about page.")
}

app.Get("/about", about)
Now if you visit http://localhost:8080/about, you will see your new page. That is it, you have built your first Mizu web server. Next, move on to Static Files to learn how to serve HTML, CSS, and images.