httpapi

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Overview

Package httpapi is the REST API of the admin listener (api/openapi.yaml, PHASE1 step 13): hand-written on net/http and encoding/json. The spec comes first; every route here is an operation of it, and the contract tests check both against each other.

Every request runs through the same chain: request ID and access log, cross-origin protection, the session (or 401), the CSRF token for changes, the JSON body rules – then the handler, which calls the services. The services check the permissions themselves (security.md); the handlers only translate between HTTP and them.

Index

Constants

View Source
const BasePath = "/api/v1"

BasePath is where the API lives on the admin listener.

View Source
const MaxBody = 128 << 10

MaxBody is the size limit of a request body (CSRs fit easily).

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	// contains filtered or unexported fields
}

API is the handler of BasePath.

func New

func New(d Deps) *API

New returns the API handler; mount it at BasePath + "/".

func (*API) Routes

func (a *API) Routes() []Route

Routes lists the operations this build serves (contract tests).

func (*API) ServeHTTP

func (a *API) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Deps

type Deps struct {
	Auth    *auth.Service
	Engine  *ca.Engine
	Keys    *keys.Keyring
	Presets *preset.Set
	Clock   clock.Clock
	Log     *slog.Logger
	// TrustedProxies may set X-Forwarded-For (auth.trusted_proxies).
	TrustedProxies []netip.Prefix
	Version        string
	Demo           bool
	// Settings are the tenant settings (step 18); Tenant is the tenant of
	// this API ("" = store.DefaultTenant).
	Settings *tenant.Store
	Tenant   string
	// TenantAudit and InstanceAudit are the audit logs for reading (step 18).
	TenantAudit, InstanceAudit *sql.DB
}

Deps are the services the API calls.

type Route

type Route struct {
	OperationID, Method, Path string // Path relative to BasePath, in spec syntax
	// contains filtered or unexported fields
}

Route is one operation of the spec.

Jump to

Keyboard shortcuts

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