jsonapi

package
v0.0.39 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package jsonapi provides HTTP middleware that transforms Vanguard REST responses into [JSON:API](https://jsonapi.org/format/) envelopes with the foundation/jsonapi codec.

Only REST requests are transformed (IsRESTRequest); Connect, gRPC, and gRPC-Web pass through unchanged. The middleware sits between the HTTP server and Vanguard, rewriting response bodies into {data, meta, links, errors} and validating/unwrapping the inbound {data:{type,attributes}} request envelope, by the Role of the route the consumer's table (codec.Config) matches.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRESTRequest

func IsRESTRequest(r *http.Request) bool

IsRESTRequest returns true if the request appears to be a REST request (not Connect, gRPC, or gRPC-Web).

func Middleware

func Middleware(
	inner http.Handler,
	cfg codec.Config,
) http.Handler

Middleware wraps an http.Handler with JSON:API response/request transformation, driven by the generated operation-keyed route table. Only REST requests are transformed; Connect, gRPC, and gRPC-Web pass through unchanged.

Request handling order is match-first: the route is resolved by (method, path) before any body handling, so an unmatched path passes through untouched. A matched CREATE/UPDATE route validates + unwraps the inbound {data:{type,attributes}} envelope (400 before the handler on a malformed, absent, or type-mismatched envelope); other roles pass their body through. The response is then transformed by the route's codec.Role — never by guessing method/path/data-presence.

Types

This section is empty.

Jump to

Keyboard shortcuts

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