Skip to main content

Query, Form, and Path

In this lesson, you will learn how to read data sent by users through query strings, form submissions, and path parameters. These are the main ways a client can send information to your server. Mizu provides simple helper methods on Ctx that make handlers easy to read and maintain.

Code

Create a file named main.go and add this code:

Run

Start your server with:
Then test the routes:
Response: Form submitted by Alice (alice@example.com)

How it works

Mizu’s Ctx helpers wrap parts of Go’s http.Request to make input handling simpler.
  • Query reads values from the URL.
  • Form parses key-value pairs from POST data.
  • Param extracts variables from the route path.
Each method returns safe, plain strings. If a key is missing, you get an empty string. If parsing fails, c.Form() returns an error you can check. These helpers keep your code short and close to Go’s net/http design.

Try something new

You can add a small HTML form to test the /submit route. Create a file named form.html:
Serve it with Mizu’s static file helper, then open it in your browser and submit the form. You will see the response from your submit handler. Now you know how to read data from query strings, forms, and path parameters in Mizu. Next, continue to Cookies to learn how to store small pieces of data between requests.