middleware

middleware is a skill for Claude Code, Codex from jkaninda/okapi-skills. It costs 0 tokens per session (1,340 once invoked), scanned A, original, MIT.

A guide to adding middleware in the Okapi Go web framework. Middleware is code that runs around web requests, such as before and after the main request handler, and can pass control to the next handler.

In plain words
What is it for?
Use it to build custom request-processing steps, pass values between middleware and handlers, measure request time, or configure built-in middleware in an Okapi application.
Why use it?
It explains the current middleware function shape and highlights the change from older Okapi versions. This helps prevent incompatible middleware code when upgrading or adding request processing.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to build custom request-processing steps, pass values between middleware and handlers, measure request time, or configure built-in middleware in an Okapi application.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/jkaninda/okapi-skills/middleware
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add jkaninda/okapi-skills --skill middleware
Clone the repo
git clone --depth 1 https://github.com/jkaninda/okapi-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for middleware

README.md
[![agentmods](https://agentmods.dev/badge/skills/jkaninda/okapi-skills/middleware.svg)](https://agentmods.dev/skills/jkaninda/okapi-skills/middleware)
Your own site
<a href="https://agentmods.dev/skills/jkaninda/okapi-skills/middleware"><img src="https://agentmods.dev/badge/skills/jkaninda/okapi-skills/middleware.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,340 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.01340
Opus 5 $0.00000 $0.00670
Sonnet 5 $0.00000 $0.00268
Haiku 4.5 $0.00000 $0.00134

Measured 8d ago against content hash 85f974475040, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

middleware scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

middleware/SKILL.md · 148 lines

How it starts

The opening of the file, as written. The whole thing — 148 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Okapi Middleware

Middleware and MiddlewareFunc are type aliases of HandlerFuncfunc(*Context) error. Inside a middleware, call c.Next() to pass control down the chain. Anything before c.Next() runs on the way in, anything after runs on the way out.

func custom(c *okapi.Context) error {
    start := time.Now()
    err := c.Next()
    log.Printf("Request took %v", time.Since(start))
    return err
}

o.Use(custom)

Signature change (v0.5.0). Middleware is no longer func(next HandlerFunc) HandlerFunc. Drop the outer wrapper and replace next(c) with c.Next():

// Before (v0.4.x)                          // After (v0.5.0+)
func mw(next okapi.HandlerFunc) okapi.HandlerFunc {   func mw(c *okapi.Context) error {
    return func(c *okapi.Context) error {                 err := c.Next()
        err := next(c)                                    return err
        return err                                    }
    }
}

A middleware that needs configuration returns a closure with the new signature: func RateLimit(rps int) okapi.Middleware { return func(c *okapi.Context) error { ... } }.

Built-in Middleware

Middleware Purpose
okapi.LoggerMiddleware Structured access logging (method, URL, IP, status, duration, referer, UA). Skips WebSocket upgrades and SSE streams. Enabled in okapi.Default().
okapi.RequestID() Reads X-Request-ID or generates a UUID; stores in context ("request_id") and echoes the header.
okapi.BasicAuth{...}.Middleware Basic auth — constant-time compare; sends WWW-Authenticate on failure.
okapi.JWTAuth{...}.Middleware JWT validation (HS256 / RS256 / JWKS), claims expression DSL, claim forwarding.
okapi.BodyLimit{MaxBytes: 1<<20}.Middleware Rejects requests larger than MaxBytes with 413.
okapi.Cors{...}.CORSHandler CORS preflight + headers (wildcards, credentials, expose headers, max-age). Usually attached via WithCors().

Read the full file on GitHub · 148 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 148 lines · 0 tokens per session scan A 85f974475040

Subscribe to this mod's changes

middleware is a skill published in the GitHub repository jkaninda/okapi-skills (3 stars, last pushed 22d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,340 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

af-xdp

AFXDP skill for high-performance XDP sockets. Use when creating AFXDP sockets, configuring UMEM and XSK rings, XDPREDIRECT programs, copy vs zero-copy mode, or comparing with DPDK. Activates on queries about AFXDP, xskumem, XDPREDIRECT, libbpf xsk, or zero-copy XDP.

mohitmishra786/low-level-dev-skills · 81 tokens

go-services

Operational skill for Go HTTP services: modules, idiomatic handlers, context cancellation, middleware, testing, and lean deployable binaries.

alivirgo/Major-AI-Skills · 29 tokens

golang-graphql

Implements GraphQL APIs in Golang using gqlgen or graphql-go. Apply when building GraphQL servers, designing schemas, writing resolvers, handling subscriptions, or integrating GraphQL with existing Go HTTP services. Also apply when the codebase imports github.com/99designs/gqlgen or github.com/graph-gophers/graphql-go.

samber/cc-skills-golang · 77 tokens

golang-pro

Implements concurrent Go patterns using goroutines and channels, designs and builds microservices with gRPC or REST, optimizes Go application performance with pprof, and enforces idiomatic Go with generics, interfaces, and robust error handling. Use when building Go applications requiring concurrent programming…

Jeffallan/claude-skills · 95 tokens

golang-grpc

Provides gRPC usage guidelines, protobuf organization, and production-ready patterns for Golang microservices. Use when implementing, reviewing, or debugging gRPC servers/clients, writing proto files, setting up interceptors, handling gRPC errors with status codes, configuring TLS/mTLS, testing with bufconn, or…

samber/cc-skills-golang · 72 tokens

golang-swagger

Golang OpenAPI/Swagger documentation with swaggo/swag — annotation comments (@Summary, @Param, @Success, @Router, @Security), swag init code generation, framework integrations (gin, echo, fiber, chi, net/http), security definitions (Bearer/JWT, OAuth2, API key), and struct tags (swaggertype, enums, example…

samber/cc-skills-golang · 146 tokens