Download the PHP package latomate07/wp-rest-route-creator without Composer
On this page you can find all versions of the php package latomate07/wp-rest-route-creator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package wp-rest-route-creator
WP Rest Route Creator
A simple and elegant way to add custom routes to your WordPress REST API for plugin and theme developers.
Features
- Easy-to-use and reusable system for adding custom routes.
- Middleware support for filtering and modifying requests before they reach their destination.
- Group routes with specific middlewares.
- Built-in preset middlewares for common use cases.
Installation
Install the package using Composer:
Usage
Here's a basic example of using the ApiRoute
class to register custom routes:
Middleware
You can add middleware to your routes for filtering and modifying requests. Here's an example using the built-in IsUserAuthenticated
middleware:
You can chain multiple middleware:
Built-in Middleware
The package includes several built-in middleware for common use cases:
IsUserAuthenticated
: Checks if the user is authenticated.RateLimiter
: Limits the number of requests per minute.Cors
: Adds Cross-Origin Resource Sharing (CORS) headers to the response.ApiKeyAuthentication
: Authenticates requests using an API key.
Custom Middleware
You can create your own custom middleware by creating a new class with a handle
method:
To use your custom middleware, add it to your routes:
Route Groups
You can group routes and apply middleware to all routes within the group:
In this example, the IsUserAuthenticated
middleware is applied to all routes within the group.
Contributing
Contributions are welcome! Please submit a pull request with your proposed changes.
License
WP Rest Route Creator is released under the MIT License. See the LICENSE file for more information.
Support
If you have any questions or need help, please open an issue on GitHub.