AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Chi Router

skill-ngxtm-devkit-chi-router · by ngxtm

Lightweight, composable Go HTTP router built on net/http.

No reviews yet
0 installs
40 views
0.0% view→install

Install

$ agentstack add skill-ngxtm-devkit-chi-router

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access Used
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-ngxtm-devkit-chi-router)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
6mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Chi Router? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Chi Router Standards

Router Setup

package main

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

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

    // Middleware
    r.Use(middleware.Logger)
    r.Use(middleware.Recoverer)
    r.Use(middleware.RequestID)
    r.Use(middleware.RealIP)

    // Routes
    r.Get("/", homeHandler)
    r.Get("/users/{id}", getUser)
    r.Post("/users", createUser)

    // Sub-routers
    r.Route("/api/v1", func(r chi.Router) {
        r.Get("/items", listItems)
        r.Post("/items", createItem)
    })

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

Handlers

// Path parameters
func getUser(w http.ResponseWriter, r *http.Request) {
    id := chi.URLParam(r, "id")
    user, err := findUser(id)
    if err != nil {
        http.Error(w, "Not found", http.StatusNotFound)
        return
    }
    json.NewEncoder(w).Encode(user)
}

// Query parameters
func listUsers(w http.ResponseWriter, r *http.Request) {
    page := r.URL.Query().Get("page")
    limit := r.URL.Query().Get("limit")
    users := fetchUsers(page, limit)
    json.NewEncoder(w).Encode(users)
}

// JSON body
func createUser(w http.ResponseWriter, r *http.Request) {
    var req CreateUserRequest
    if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
        http.Error(w, err.Error(), http.StatusBadRequest)
        return
    }
    user := insertUser(req)
    w.WriteHeader(http.StatusCreated)
    json.NewEncoder(w).Encode(user)
}

Middleware

// Built-in middleware
r.Use(middleware.Logger)          // Logs requests
r.Use(middleware.Recoverer)       // Panic recovery
r.Use(middleware.RequestID)       // Request ID header
r.Use(middleware.RealIP)          // Real IP from headers
r.Use(middleware.Compress(5))     // Gzip compression
r.Use(middleware.Timeout(60 * time.Second))

// Custom middleware
func authMiddleware(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        token := r.Header.Get("Authorization")
        if token == "" {
            http.Error(w, "Unauthorized", http.StatusUnauthorized)
            return
        }

        user, err := validateToken(token)
        if err != nil {
            http.Error(w, "Invalid token", http.StatusUnauthorized)
            return
        }

        ctx := context.WithValue(r.Context(), "user", user)
        next.ServeHTTP(w, r.WithContext(ctx))
    })
}

// Apply to group
r.Route("/api", func(r chi.Router) {
    r.Use(authMiddleware)
    r.Get("/protected", protectedHandler)
})

Route Groups & Nesting

r.Route("/api/v1", func(r chi.Router) {
    // All routes here prefixed with /api/v1

    r.Route("/users", func(r chi.Router) {
        r.Get("/", listUsers)
        r.Post("/", createUser)

        r.Route("/{id}", func(r chi.Router) {
            r.Get("/", getUser)
            r.Put("/", updateUser)
            r.Delete("/", deleteUser)
        })
    })

    r.Route("/items", func(r chi.Router) {
        r.Get("/", listItems)
    })
})

Mount Sub-Routers

func main() {
    r := chi.NewRouter()
    r.Mount("/api/v1", apiRouter())
    r.Mount("/admin", adminRouter())
    http.ListenAndServe(":8080", r)
}

func apiRouter() chi.Router {
    r := chi.NewRouter()
    r.Get("/users", listUsers)
    r.Post("/users", createUser)
    return r
}

func adminRouter() chi.Router {
    r := chi.NewRouter()
    r.Use(adminAuthMiddleware)
    r.Get("/stats", getStats)
    return r
}

Context Values

// Set in middleware
ctx := context.WithValue(r.Context(), "user", user)
next.ServeHTTP(w, r.WithContext(ctx))

// Get in handler
user := r.Context().Value("user").(*User)

// Type-safe context keys
type contextKey string
const userKey contextKey = "user"

ctx := context.WithValue(r.Context(), userKey, user)
user := r.Context().Value(userKey).(*User)

Response Helpers

import "github.com/go-chi/render"

type UserResponse struct {
    ID    int    `json:"id"`
    Name  string `json:"name"`
}

func (u *UserResponse) Render(w http.ResponseWriter, r *http.Request) error {
    return nil
}

func getUser(w http.ResponseWriter, r *http.Request) {
    user := &UserResponse{ID: 1, Name: "John"}
    render.Render(w, r, user)
}

// Error response
func ErrNotFound(w http.ResponseWriter, r *http.Request, err error) {
    render.Status(r, http.StatusNotFound)
    render.JSON(w, r, map[string]string{"error": err.Error()})
}

Best Practices

  1. Standard library: Chi uses net/http, fully compatible with standard handlers
  2. Composition: Use r.Route() for grouping, r.Mount() for sub-routers
  3. Middleware order: Apply in order of execution (outer to inner)
  4. Context: Use typed keys for context values
  5. Testing: Use httptest - Chi handlers are standard http.Handler

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.