Download the PHP package rdelbem/routepress without Composer
On this page you can find all versions of the php package rdelbem/routepress. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rdelbem/routepress
More information about rdelbem/routepress
Files in rdelbem/routepress
Package routepress
Short Description A WordPress lib to create APIs easily
License GPL-3.0-or-later
Informations about the package routepress
Routepress
A PHP library to simplify the creation and management of WordPress REST API routes.
Table of Contents
- Introduction
- Features
- Installation
- Requirements
- Usage
- Implementing the AuthInterface
- Initializing Routepress
- Creating Routes
- Examples
- Simple GET Route
- POST Route with Authentication
- Multiple HTTP Verbs
- Testing
- Contributing
- License
Introduction
Routepress is a PHP library designed to streamline the process of registering and managing REST API routes in WordPress plugins. It provides a fluent interface for defining routes, handling callbacks, and integrating custom authentication mechanisms.
Features
- Simplified Route Registration: Easily create REST API routes with minimal code.
- HTTP Verb Support: Handle various HTTP methods like GET, POST, PUT, DELETE, and more.
- Custom Authentication: Integrate your own authentication logic through the
AuthInterface
. - Namespacing: Organize your routes under a specific namespace.
- Callback Handling: Define callbacks for route responses effortlessly.
Installation
Install Routepress via Composer:
bash
composer require rdelbem/routepress
Requirements
- PHP 8.1 or higher
- WordPress 5.6 or higher
- Composer
Usage
Implementing the AuthInterface
Create a class that implements the AuthInterface
to define your custom authentication logic:
Initializing Routepress
Instantiate the Routepress
class with your authentication class and API namespace:
php
Creating Routes
Use the create
method to define a new route:
- $httpVerb: The HTTP method(s) (e.g., 'GET', 'POST', or an array of methods).
- $route: The endpoint route (e.g., '/my-route').
- $callback: The function to execute when the route is accessed.
- $authenticationRequired: Whether authentication is required (default is
false
).
Examples
Simple GET Route
POST Route with Authentication
Multiple HTTP Verbs
Testing
Routepress includes a suite of tests to ensure reliability.
Running Tests
Make sure you have Docker and Docker Compose installed. Then, run:
Static Analysis with Psalm
Run Psalm to perform static analysis:
Contributing
Contributions are welcome! Please follow these steps:
-
Fork the Repository: Click the "Fork" button at the top right of the repository page.
-
Clone Your Fork:
-
Create a New Branch:
-
Make Your Changes: Implement your feature or bug fix.
-
Commit Your Changes:
-
Push to Your Branch:
- Submit a Pull Request: Go to the original repository and click "New Pull Request".
Coding Standards
- Follow PSR-12 coding standards.
- Ensure all tests pass before submitting.
- Write unit and/or integration tests for new features.
License
Routepress is open-source software licensed under the GNU General Public License v3.0 or later.
Disclaimer: This project is not affiliated with or endorsed by WordPress. "WordPress" is a registered trademark of the WordPress Foundation.