PHPackages                             rdelbem/routepress - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. rdelbem/routepress

ActiveLibrary[API Development](/categories/api)

rdelbem/routepress
==================

A WordPress lib to create APIs easily

1.0.0(1y ago)02GPL-3.0-or-laterPHP

Since Oct 5Pushed 1y ago1 watchersCompare

[ Source](https://github.com/rdelbem/Routepress)[ Packagist](https://packagist.org/packages/rdelbem/routepress)[ RSS](/packages/rdelbem-routepress/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (9)Versions (5)Used By (0)

Routepress
==========

[](#routepress)

[![Build Status](https://github.com/rdelbem/routepress/actions/workflows/ci.yml/badge.svg)](https://github.com/rdelbem/routepress/actions)

A PHP library to simplify the creation and management of WordPress REST API routes.

Table of Contents
-----------------

[](#table-of-contents)

- [Introduction](#introduction)
- [Features](#features)
- [Installation](#installation)
- [Requirements](#requirements)
- [Usage](#usage)
    - [Implementing the AuthInterface](#implementing-the-authinterface)
    - [Initializing Routepress](#initializing-routepress)
    - [Creating Routes](#creating-routes)
- [Examples](#examples)
    - [Simple GET Route](#simple-get-route)
    - [POST Route with Authentication](#post-route-with-authentication)
    - [Multiple HTTP Verbs](#multiple-http-verbs)
- [Testing](#testing)
- [Contributing](#contributing)
- [License](#license)

Introduction
------------

[](#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
--------

[](#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
------------

[](#installation)

Install Routepress via Composer:

bash

`composer require rdelbem/routepress`

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- WordPress 5.6 or higher
- Composer

Usage
-----

[](#usage)

### Implementing the AuthInterface

[](#implementing-the-authinterface)

Create a class that implements the `AuthInterface` to define your custom authentication logic:

```
use Rdelbem\Routepress\AuthInterface;
use Rdelbem\Routepress\Types\AuthHeader;
use WP_User;

class MyAuth implements AuthInterface {
    public function validateRefreshToken(string $refreshToken): bool {
        // Your validation logic
    }

    public function createSession(WP_User $user): void {
        // Create a user session
    }

    public function generateJwtAtLogin(): void {
        // Generate JWT upon user login
    }

    public function generateAuthHeader(): AuthHeader {
        // Generate and return an AuthHeader object
    }

    public function removeJwt(): void {
        // Remove JWT token
    }
}
```

### Initializing Routepress

[](#initializing-routepress)

Instantiate the `Routepress` class with your authentication class and API namespace:

php

```
use Rdelbem\Routepress\Routepress;

$auth = new MyAuth();
$routepress = new Routepress($auth, 'myplugin/v1');`
```

### Creating Routes

[](#creating-routes)

Use the `create` method to define a new route:

```
$routepress->create(
    string|array $httpVerb,
    string $route,
    callable $callback,
    bool $authenticationRequired = false
);
```

- **$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
--------

[](#examples)

### Simple GET Route

[](#simple-get-route)

```
$routepress->create('GET', '/hello', function () {
    return ['message' => 'Hello, World!'];
});
```

### POST Route with Authentication

[](#post-route-with-authentication)

```
$routepress->create('POST', '/submit', function ($request) {
    $data = $request->get_params();
    // Process the data
    return ['status' => 'success'];
}, true);
```

### Multiple HTTP Verbs

[](#multiple-http-verbs)

```
$routepress->create(['GET', 'POST'], '/data', function ($request) {
    if ($request->get_method() === 'GET') {
        return ['data' => 'Some data'];
    } else {
        // Handle POST request
    }
});
```

Testing
-------

[](#testing)

Routepress includes a suite of tests to ensure reliability.

### Running Tests

[](#running-tests)

Make sure you have Docker and Docker Compose installed. Then, run:

```
docker compose up -d --build
docker compose exec php vendor/bin/codecept run wpunit
```

### Static Analysis with Psalm

[](#static-analysis-with-psalm)

Run Psalm to perform static analysis:

```
docker compose exec php vendor/bin/psalm
```

Contributing
------------

[](#contributing)

Contributions are welcome! Please follow these steps:

1. **Fork the Repository**: Click the "Fork" button at the top right of the repository page.
2. **Clone Your Fork**:

    ```
    git clone https://github.com/yourusername/routepress.git
    ```
3. **Create a New Branch**:

    ```
    git checkout -b feature/your-feature-name
    ```
4. **Make Your Changes**: Implement your feature or bug fix.
5. **Commit Your Changes**:

    ```
    git commit -am 'Add new feature'
    ```
6. **Push to Your Branch**:

    ```
    git push origin feature/your-feature-name
    ```
7. **Submit a Pull Request**: Go to the original repository and click "New Pull Request".

### Coding Standards

[](#coding-standards)

- Follow PSR-12 coding standards.
- Ensure all tests pass before submitting.
- Write unit and/or integration tests for new features.

License
-------

[](#license)

Routepress is open-source software licensed under the [GNU General Public License v3.0 or later](https://spdx.org/licenses/GPL-3.0-or-later.html).

---

**Disclaimer**: This project is not affiliated with or endorsed by WordPress. "WordPress" is a registered trademark of the WordPress Foundation.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

581d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8c8db776d3e8c20972e78cb09748a74b12fc6e96b1bdba7b4938067462c95be1?d=identicon)[rdelbem](/maintainers/rdelbem)

---

Top Contributors

[![rdelbem](https://avatars.githubusercontent.com/u/5652782?v=4)](https://github.com/rdelbem "rdelbem (19 commits)")

###  Code Quality

TestsCodeception

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rdelbem-routepress/health.svg)

```
[![Health](https://phpackages.com/badges/rdelbem-routepress/health.svg)](https://phpackages.com/packages/rdelbem-routepress)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M475](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M270](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M452](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
