Get up and running with Mux in under 5 minutes. This guide shows the smallest useful slice of the framework using its default startup path.
New to Mux? This quick start gets you coding immediately. For a comprehensive tutorial, see the Interactive Tutorial.
- Go 1.25.6 or later installed (Download)
- Basic familiarity with Go
mkdir my-api
cd my-api
go mod init my-api
go get github.com/fgrzl/muxCreate main.go:
package main
import (
"context"
"os"
"os/signal"
"syscall"
"github.com/fgrzl/mux"
)
func main() {
router := mux.NewRouter()
if err := router.Configure(func(router *mux.Router) {
router.GET("/hello", func(c mux.RouteContext) {
c.OK("Hello, World!")
})
}); err != nil {
panic(err)
}
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
server := mux.NewServer(":8080", router)
if err := server.Listen(ctx); err != nil {
panic(err)
}
}Configure is the recommended startup path: it runs route registration in non-panicking validation mode and returns configuration errors directly.
If you are migrating existing net/http code, Handle and HandleFunc let you keep standard-library handlers and only opt into mux.RouteContextFromRequest(r) when you need route params, scoped services, or other framework features.
# Run the server
go run .
# In another terminal, test it
curl http://localhost:8080/helloOutput: "Hello, World!"
Congratulations! You have a working API!
Choose your path:
Interactive Tutorial - Build a complete Todo API in 30 minutes with validation, error handling, and OpenAPI documentation.
Getting Started - Step-by-step guide covering all major features with examples.
Cheat Sheet - Copy-paste examples for common patterns.
Learning Path - Progressive 8-level course from beginner to advanced.
- Installation - Detailed setup and requirements
- Router - Routing fundamentals and configuration
- Middleware - Built-in middleware guide
Check out the other documentation files to learn about advanced features like authentication, custom middleware, and production deployment patterns.