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