PHP · WORDPRESS REST API
rest-api-examples — Production WordPress REST API (WP-JSON) Endpoint Blueprints
rest-api-examples is a reference library of secure, schema-validated custom WordPress REST API endpoints built with register_rest_route(). It demonstrates custom permission callbacks, nonce and application-password authentication, WP_Query pagination headers, and transient response caching.
$ wp plugin activate rest-api-examples
Copy
GitHub ↗
Schema Validation
Strict JSON Schema
Auth Methods
Nonce / App Passwords
Cache Headers
ETag + Surrogate-Key
PHPStan Level
Level 8 Clean
01. Interactive Workbench
02. Reference Implementation
03. Architecture & Specs
Interactive `register_rest_route` Endpoint & Schema Generator
REST Namespace & Route Pattern
HTTP Method & Permission Guard
GET — Public Cached Read with Surrogate-Key Header
POST — `current_user_can('edit_posts')` + Strict Arg Sanitization
DELETE — `manage_options` Administrator Guard + Audit Log
WP_REST_Server::READABLE Paginated Collection (`X-WP-Total`)
Execute Pipeline ▶
Reset
Deterministic Execution Output & Telemetry
STATUS: READY // 0 ERRORS
PHP (WordPress REST API Route)
add_action( 'rest_api_init', function () {
register_rest_route( 'bhubbard/v1', '/reports/(?P<id>\d+)', [
'methods' => WP_REST_Server::READABLE,
'callback' => 'bhubbard_get_report_endpoint',
'permission_callback' => function () {
return current_user_can( 'edit_posts' );
},
'args' => [
'id' => [ 'validate_callback' => fn( $param ) => is_numeric( $param ) ],
],
] );
} );
Production Engineering Specifications
Repository: https://github.com/bhubbard/rest-api-examples
Live Studio: https://code.brandonhubbard.com/rest-api-examples/
Portal: https://code.brandonhubbard.com/
Install: wp plugin activate rest-api-examples
Design System: Brandon Hubbard Swiss Modernist (#0A0A0C / 1px Exposed Structural Grid)