Brandon Hubbard Engineering / rest-api-examples
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
GitHub ↗
Schema Validation Strict JSON Schema
Auth Methods Nonce / App Passwords
Cache Headers ETag + Surrogate-Key
PHPStan Level Level 8 Clean
Interactive `register_rest_route` Endpoint & Schema Generator
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)