Documentation
¶
Overview ¶
Package api contains the REST API for ToolHive.
Index ¶
- func DocsRouter() http.Handler
- func GenerateNonce() (string, error)
- func ServeOpenAPI(w http.ResponseWriter, _ *http.Request)
- func ServeScalar(w http.ResponseWriter, _ *http.Request)
- type Server
- type ServerBuilder
- func (b *ServerBuilder) Build(ctx context.Context) (*chi.Mux, error)
- func (b *ServerBuilder) WithAddress(address string) *ServerBuilder
- func (b *ServerBuilder) WithDebugMode(debugMode bool) *ServerBuilder
- func (b *ServerBuilder) WithDocs(enableDocs bool) *ServerBuilder
- func (b *ServerBuilder) WithMiddleware(mw ...func(http.Handler) http.Handler) *ServerBuilder
- func (b *ServerBuilder) WithNonce(nonce string) *ServerBuilder
- func (b *ServerBuilder) WithOIDCConfig(oidcConfig *auth.TokenValidatorConfig) *ServerBuilder
- func (b *ServerBuilder) WithOtelEnabled(enabled bool) *ServerBuilder
- func (b *ServerBuilder) WithRoute(prefix string, handler http.Handler) *ServerBuilder
- func (b *ServerBuilder) WithUnixSocket(isUnixSocket bool) *ServerBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DocsRouter ¶ added in v0.0.35
DocsRouter creates a new router for documentation endpoints.
func GenerateNonce ¶ added in v0.15.0
GenerateNonce generates a random nonce for server instance identification.
func ServeOpenAPI ¶ added in v0.0.35
func ServeOpenAPI(w http.ResponseWriter, _ *http.Request)
ServeOpenAPI writes the OpenAPI specification as JSON to the response. @Summary Get OpenAPI specification @Description Returns the OpenAPI specification for the API @Tags system @Produce json @Success 200 {object} object "OpenAPI specification" @Router /api/openapi.json [get]
func ServeScalar ¶ added in v0.0.35
func ServeScalar(w http.ResponseWriter, _ *http.Request)
ServeScalar serves the Scalar API reference page
Types ¶
type Server ¶ added in v0.2.10
type Server struct {
// contains filtered or unexported fields
}
Server represents a configured HTTP server
func NewServer ¶ added in v0.2.10
func NewServer(ctx context.Context, builder *ServerBuilder) (*Server, error)
NewServer creates a new Server instance from a pre-configured builder
type ServerBuilder ¶ added in v0.2.10
type ServerBuilder struct {
// contains filtered or unexported fields
}
ServerBuilder provides a fluent interface for building and configuring the API server
func NewServerBuilder ¶ added in v0.2.10
func NewServerBuilder() *ServerBuilder
NewServerBuilder creates a new ServerBuilder with default configuration
func (*ServerBuilder) WithAddress ¶ added in v0.2.10
func (b *ServerBuilder) WithAddress(address string) *ServerBuilder
WithAddress sets the server address
func (*ServerBuilder) WithDebugMode ¶ added in v0.2.10
func (b *ServerBuilder) WithDebugMode(debugMode bool) *ServerBuilder
WithDebugMode enables or disables debug mode
func (*ServerBuilder) WithDocs ¶ added in v0.2.10
func (b *ServerBuilder) WithDocs(enableDocs bool) *ServerBuilder
WithDocs enables or disables OpenAPI documentation
func (*ServerBuilder) WithMiddleware ¶ added in v0.2.10
func (b *ServerBuilder) WithMiddleware(mw ...func(http.Handler) http.Handler) *ServerBuilder
WithMiddleware appends HTTP middleware that runs after the default middleware stack (request-ID, body-size limit, headers, update-check, auth) and before route handlers. Part of the ApplyServerExtensions extension point — used by downstream consumers to inject custom authentication or request-scoping middleware into the API server.
Public extension API. Do not remove based on deadcode analysis alone: callers may live in repositories that are not visible to this module's analyzer. The test in server_test.go intentionally exercises this method to keep it reachable.
func (*ServerBuilder) WithNonce ¶ added in v0.13.0
func (b *ServerBuilder) WithNonce(nonce string) *ServerBuilder
WithNonce sets the server instance nonce used for discovery verification. When non-empty, the server writes a discovery file on startup and returns the nonce in the X-Toolhive-Nonce health check header.
func (*ServerBuilder) WithOIDCConfig ¶ added in v0.2.10
func (b *ServerBuilder) WithOIDCConfig(oidcConfig *auth.TokenValidatorConfig) *ServerBuilder
WithOIDCConfig sets the OIDC configuration
func (*ServerBuilder) WithOtelEnabled ¶ added in v0.15.0
func (b *ServerBuilder) WithOtelEnabled(enabled bool) *ServerBuilder
WithOtelEnabled enables OTEL HTTP middleware for distributed tracing. When enabled, the server extracts W3C traceparent headers from incoming requests and creates child OTEL spans for each request. Requires OTEL to be initialized (via telemetry.NewProvider) before the server starts.
func (*ServerBuilder) WithRoute ¶ added in v0.2.10
func (b *ServerBuilder) WithRoute(prefix string, handler http.Handler) *ServerBuilder
WithRoute mounts a sub-router at the given prefix. The caller is responsible for any per-route timeout middleware. Part of the ApplyServerExtensions extension point — used by downstream consumers to add API surface alongside the built-in routes.
Public extension API. Do not remove based on deadcode analysis alone: callers may live in repositories that are not visible to this module's analyzer. The test in server_test.go intentionally exercises this method to keep it reachable.
func (*ServerBuilder) WithUnixSocket ¶ added in v0.2.10
func (b *ServerBuilder) WithUnixSocket(isUnixSocket bool) *ServerBuilder
WithUnixSocket configures the server to use a Unix socket