better-route Documentation
better-route is a Composer-first WordPress REST contract layer for teams that need stable, versioned APIs.
Status
- Baseline documentation target:
v0.6.0 - Latest release:
v0.6.0 - Previous release:
v0.5.0 - Packagist/package index release: not published yet — install via VCS repository
What you get
- Fluent router on top of
register_rest_route(), with explicitOPTIONSroute support for preflight - Middleware pipeline with deterministic order:
global -> group -> route - Resource DSL for CPT and custom table endpoints, with write-validation schemas, field-level policies, and
ResourcePolicy/OwnedResourcePolicypresets - Strict query contract (
unknown params => 400) - Unified error envelope with
requestId(no internal exception leakage on 5xx), plus opt-in OAuth RFC 6749 error format per route (v0.6.0) - Built-in auth, write-safety, and observability middleware
- Identity primitives (v0.6.0):
Rs256JwksJwtVerifierfor OIDC providers (RS256/ES256),HmacSignatureMiddlewarefor signed webhooks,SingleUseTokenMiddlewarefor OAuth codes / magic links,Cryptohelper for tokens and constant-time compare - Network primitives (v0.6.0):
TrustedProxyClientIpResolverandIpAllowlistMiddlewarewith IPv4/IPv6 CIDR matching - Public-client primitives (v0.5.0):
CorsMiddleware/CorsPolicy,AtomicIdempotencyMiddlewarewithwpdbreservation store,OwnershipGuardMiddleware, andAuditEnricherMiddleware - OpenAPI MVP exporter with security scheme support,
strictSchemasmode, and optionalopenapi.jsonendpoint (admin-only by default) - WooCommerce integration: Orders, Products, Customers, Coupons with full CRUD, query parsing, HPOS guard, capability-checked writes, protected meta keys, configurable
deleteMode, and pre-built OpenAPI component schemas
Who this is for
- WordPress teams building headless APIs
- Plugin/app teams that want contract-first endpoints
- Integrations where schema, error shape, and policy behavior must stay predictable
- Teams wrapping OIDC or OAuth providers, signed webhook callers, or partner integrations with strict network boundaries
- WooCommerce stores that need a typed, middleware-aware REST layer over core WC data
What this is not
- Not a UI plugin with admin pages
- Not a no-code endpoint builder
- Not a WooCommerce replacement — it exposes WC data through a stricter contract
- Not a token issuer / refresh-token rotator / login flow —
better-routeverifies credentials supplied by another layer
Documentation map
Start with:
Getting Startedfor install + first route/resourceCorefor router, middleware lifecycle, error contractResourcesfor CPT/table DSL and query safetyAuthfor JWT (HS256 + JWKS), HMAC signatures, application passwords, cookie/nonce, bearer token, ownership guardWrite Safetyfor idempotency (replay + atomic), single-use tokens, and optimistic lockingNetworkfor trusted-proxy IP resolution and CIDR allowlistsPublic-Client APIsfor CORS, preflight, and the OAuth error formatSupportfor shared crypto utilitiesWooCommercefor orders, products, customers, coupons integrationOpenAPIfor schema export, security schemes, and endpoint publishingReferencefor API tables and middleware catalogAI Agent Skillsfor structured skills an AI agent can use to work with the libraryRelease Notesfor what changed in each version