Download the PHP package mrldavies/wp-rest-fluent without Composer
On this page you can find all versions of the php package mrldavies/wp-rest-fluent. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package wp-rest-fluent
wp-rest-fluent
A fluent routing layer for the WordPress REST API with middleware, groups and response formatting.
Inspired by Laravel-style routing and middleware patterns, adapted for WordPress.
Requirements
- PHP >= 8.1
- WordPress (must run inside a WP environment)
If using Roots Sage, v10 or above is required.
Installation
Install via Composer:
Basic Usage
Import the class:
Define your routes:
Register routes during boot:
Using with Roots Sage (v10+)
If using Roots Sage v10 or above (Acorn-based), register routes inside a service provider.
Example:
Ensure your provider is registered in config/app.php.
This works because Acorn bootstraps WordPress hooks correctly within the container lifecycle.
HTTP Methods
Route Parameters
You can define typed parameters using curly braces:
Supported built-in types
int→[0-9]+alpha→[a-zA-Z]+- default (no type) →
[a-zA-Z0-9-+_]+
Example:
Optional parameter:
Advanced / Raw Regex Routes
If you require full regex control, you can bypass the curly-brace syntax entirely and use native WordPress-style patterns:
This gives complete control over route matching.
Response Handling
Your handler may return:
Array
Object
Returning WP Native Responses
You may also return:
WP_REST_ResponseWP_Error
These will be passed through untouched.
Formatter
Enable formatted responses:
Output shape:
Mapping Custom Response Shapes
If your handler returns a different structure:
Map it:
Middleware
Attach middleware to routes:
Middleware follows the same conceptual structure as Laravel middleware.
Laravel middleware documentation: https://laravel.com/docs/middleware
Your middleware must implement:
To continue the chain:
Middleware may return:
WP_REST_ResponseWP_Error- Or allow execution to continue
Middleware execution order is LIFO (last attached runs closest to the handler).
Shipped Middleware
RateLimitMiddleware
The package includes a simple transient-based rate limiter.
Example:
Features:
- Per-IP limiting
- Per-user limiting when logged in
- Sliding window
- Returns HTTP 429 with
Retry-Afterheader
The rate limiter is provided as a convenience and can be replaced or extended.
Route Groups
Group routes under shared configuration:
You may also group middleware and permissions:
Permissions
Attach permission callbacks:
Permission callbacks must return:
truefalse- or
WP_Error
Custom Namespace Prefix
Default namespace prefix is v1.
Override per-route:
Debugging Routes
Inspect registered routes:
Notes
- Designed specifically for WordPress REST API.
- Requires WordPress runtime.
- Middleware architecture mirrors Laravel's pipeline concept.
- Supports array and object response normalization.
- Allows full custom WordPress regex routes when needed.
License
MIT