httpapi

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package httpapi is the HTTP frontend, implemented on the standard library only (net/http with method-pattern routing). It turns the registry's HTTP hints into routes:

  • HTTPHints.Method + Path define the route; path placeholders {name} map to fields tagged http:"path" (via r.PathValue).
  • 未标注 http 位置或标注 http:"query" 的字段默认从 query 绑定; http:"header"(httpName)从请求头绑定;JSON body 合并为入参基底。
  • Responses are bare JSON (no envelope), the same shape as CLI --json; errors map to HTTP status codes through the shared error taxonomy.
  • GET /openapi.json exposes an OpenAPI 3 document generated from the same InputSchema the MCP frontend uses.

Entries without HTTP hints are not routed. This package pulls zero third-party dependencies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bearer

func Bearer(tokens []string, h http.Handler) http.Handler

func CORS

func CORS(origins []string, h http.Handler) http.Handler

CORS wraps h with permissive-allowlist CORS handling: requests whose Origin matches an entry in origins (or "*" for any origin) get the Access-Control-Allow-Origin header, and OPTIONS preflights are answered with 204 before reaching the inner handler. Empty origins disables CORS.

func Gzip

func Gzip(h http.Handler) http.Handler

Gzip transparently compresses responses for clients that send Accept-Encoding: gzip. Mount it inside auth (compression is per-request and must come after the credentials check).

func Handler

func Handler(reg *registry.Registry) (http.Handler, error)

Handler builds the router for registered HTTP routes plus /openapi.json. Conflicting method+path registrations are errors.

func HandlerFor added in v0.2.0

func HandlerFor(e *spec.Entry) http.HandlerFunc

HandlerFor returns the standalone handler for one registered entry: the full binding (query/path/header/body) and error mapping, without routing. Mount it onto any router (gin.WrapH, echo, chi) or wrap it with your own middleware; Handler below composes all routed entries plus /healthz and /openapi.json.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL