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 CORS ¶
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 ¶
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 ¶
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.