Skip to content

Latest commit

 

History

History
100 lines (67 loc) · 2.63 KB

File metadata and controls

100 lines (67 loc) · 2.63 KB

Quick Start

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.

Prerequisites

  • Go 1.25.6 or later installed (Download)
  • Basic familiarity with Go

Step 1: Create a New Project

mkdir my-api
cd my-api
go mod init my-api
go get github.com/fgrzl/mux

Step 2: Create Your First API

Create 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.

Step 3: Run and Test

# Run the server
go run .

# In another terminal, test it
curl http://localhost:8080/hello

Output: "Hello, World!"

Congratulations! You have a working API!

What's Next?

Choose your path:

Learn by Doing

Interactive Tutorial - Build a complete Todo API in 30 minutes with validation, error handling, and OpenAPI documentation.

Comprehensive Guide

Getting Started - Step-by-step guide covering all major features with examples.

Quick Reference

Cheat Sheet - Copy-paste examples for common patterns.

Structured Learning

Learning Path - Progressive 8-level course from beginner to advanced.

See Also

Check out the other documentation files to learn about advanced features like authentication, custom middleware, and production deployment patterns.