api

package
v0.401.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package api provides a framework-free HTTP handler for the GOBL API. It wraps the internal/ops functions and exposes them as standard net/http endpoints, suitable for use in any HTTP server.

Use NewHandler to build an http.Handler with all GOBL API routes. Options allow enabling the MCP endpoint, the built-in favicon, or registering custom routes on the underlying ServeMux.

Index

Constants

This section is empty.

Variables

View Source
var VersionPrefix = "v" + fmt.Sprintf("%d", gobl.VERSION.Semver().Major())

VersionPrefix is the major-version path prefix derived from gobl.VERSION, e.g. "v0" for "v0.400.0-rc1".

Functions

func NewHandler

func NewHandler(opts ...Option) http.Handler

NewHandler builds and returns an http.Handler with GOBL API routes registered under the major-version prefix (e.g. /v0/build).

By default the handler includes document operations (build, validate, correct, replicate, sign, verify), reference data (schemas, regimes, addons), key generation, the OpenAPI spec, and a version/health endpoint. CORS, version-header, timing, and logging middleware are always applied.

Use WithMCP, WithFavicon, and WithRoutes to enable additional functionality.

func WithETag

func WithETag(h http.HandlerFunc) http.HandlerFunc

WithETag wraps a handler func to set an ETag header based on the GOBL version and return 304 Not Modified when the client already has the current version cached.

func WriteError

func WriteError(w http.ResponseWriter, err error)

WriteError writes a JSON error response. The HTTP status is derived from the error's Key using httpStatusForKey. Useful for custom route handlers that need to produce consistent error responses.

func WriteJSON

func WriteJSON(w http.ResponseWriter, v any)

WriteJSON writes a JSON response with 200 OK status.

func WriteRawJSON

func WriteRawJSON(w http.ResponseWriter, d []byte)

WriteRawJSON writes pre-encoded JSON bytes as a response.

Types

type Option

type Option func(*config)

Option configures the handler returned by NewHandler.

func WithFavicon

func WithFavicon() Option

WithFavicon enables the built-in /favicon.svg handler.

func WithMCP

func WithMCP() Option

WithMCP enables the MCP (Model Context Protocol) endpoint at /<version>/mcp.

func WithRoutes

func WithRoutes(fn func(mux *http.ServeMux, prefix string)) Option

WithRoutes allows the caller to register additional routes on the handler's ServeMux. The prefix argument is the version path prefix (e.g. "/v0") so callers can mount routes alongside the API.

Jump to

Keyboard shortcuts

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