Chi + EdgeOne Pages

Build composable web applications with Chi router. Features composable middleware, subrouters, URL parameters, and idiomatic Go patterns.

cloud-functions/api.go
package main

import (
    "github.com/go-chi/chi/v5"
    "github.com/go-chi/chi/v5/middleware"
)

func main() {
    r := chi.NewRouter()

    r.Use(middleware.Recoverer)
    r.Use(middleware.Logger)

    r.Get("/", welcomeHandler)
    r.Get("/health", healthHandler)

    // Todo CRUD subrouter
    r.Route("/api/todos", func(r chi.Router) {
        r.Get("/", listTodos)
        r.Post("/", createTodo)
        r.Get("/{id}", getTodo)
        r.Patch("/{id}/toggle", toggleTodo)
        r.Delete("/{id}", deleteTodo)
    })

    http.ListenAndServe(":9000", r)
}

API Endpoints

GET/api/

Welcome page listing all available routes

GET/api/health

Health check endpoint returning service status

GET/api/api/todos

GET route returning all todos with total count

POST/api/api/todos

POST route with JSON body to create a new todo

Request Body:

{
  "title": "Learn Chi Router"
}
GET/api/api/todos/1

Dynamic route parameter with chi.URLParam(r, "id")

PATCH/api/api/todos/1/toggle

Toggle todo completion status

DELETE/api/api/todos/3

Delete a todo by ID

Composable Middleware

Stack middleware with Use() for clean, reusable request processing

Subrouters

Organize routes with nested subrouters and route groups

net/http Compatible

100% compatible with Go standard library net/http