PHPackages                             hc/rest-routes - 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. hc/rest-routes

ActiveWordpress-plugin[API Development](/categories/api)

hc/rest-routes
==============

Rest API Routes for Wordpress.

v1.0.0(4y ago)01.5kPHP

Since Feb 15Pushed 4y ago1 watchersCompare

[ Source](https://github.com/howatsonco/hc-rest-routes)[ Packagist](https://packagist.org/packages/hc/rest-routes)[ RSS](/packages/hc-rest-routes/feed)WikiDiscussions prod Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

Introduction
============

[](#introduction)

A plugin for custom API routing. Made with love by Howatson+Co.

Usage
=====

[](#usage)

There are two parts to using this plugin:

1. Defining API routes
2. Defining custom controllers for handling response logic

To do either of these, you will need to first access the Rest API `Server` class instance. This can be achieved either by calling the global scope function `HCRR` like this:

```
$server = HCRR();

```

Or, by accessing the global scope variable assigned:

```
global $hcrr;

```

Defining Routes
---------------

[](#defining-routes)

You can define a route through the `registerRoute` method attached to the `Router` class, like so:

```
$server->router->registerRoute("/test", "\TestController", "index");

```

The `registerRoute` method takes three arguments:

- API URI pattern to be matched for this route to be executed. This can be a regex string.
- Name of Controller to instantiate.
- Name of method attached to Controller to execute.

Defining Controllers
--------------------

[](#defining-controllers)

When defining Controllers, adhere to the following rules:

- The controller must extend `\HC\RestRoutes\Abstracts\ControllerAbstract`
- Controller methods should be named `${name}_${httpVerb}`, where:
    - `name` is the name you pass to the route, and
    - `httpVerb` is the HTTP verb of the request (e.g `GET`, `POST`, `PUT`, etc)
- `Return` the data you want to respond with.
- Throw a `RestfulException` provided by the `RestRoutes` plugin to handle exceptions.

See example below:

```
class TestController extends \HC\RestRoutes\Abstracts\ControllerAbstract
{
  public function index_get()
  {
    $posts = get_posts();

    // This will send a 200 response to the client side
    // with the data payload attached
    if (!empty($posts)) {
      return $posts;
    }

    // Otherwise, you can handle exceptions like this
    throw new \HC\RestRoutes\Exceptions\NotFoundException("No posts found.");
  }
}

```

Next, we will need to register the controller.

To register the Controller, use the `ControllerFactory` class `register` method:

```
$server->router->controllerFactory->register("\TestController");

```

Full example
------------

[](#full-example)

Bringing it all together, an example could look like this:

```
class TestController extends \HC\RestRoutes\Abstracts\ControllerAbstract
{
  public function index_get()
  {
    $posts = get_posts();

    // This will send a 200 response to the client side
    // with the data payload attached
    if (!empty($posts)) {
      return $posts;
    }

    // Otherwise, you can handle exceptions like this
    throw new \HC\RestRoutes\Exceptions\NotFoundException("No posts found.");
  }
}

$server = HCRR();
$server->router->controllerFactory->register("\TestController");
$server->router->registerRoute("/test", "\TestController", "index");

```

Extra
-----

[](#extra)

### Authorisation

[](#authorisation)

To ensure an endpoint only gives the full payload to a user who is authorised, you can use the `validateAdmin` and `validateEditor` methods which are attached to the `\HC\RestRoutes\Abstracts\ControllerAbstract` class.

### Defining API prefix

[](#defining-api-prefix)

The default API prefix is `/api/hcrr`. You can customise this by using the `setPrefix` method on the `\HC\RestRoutes\Router` class:

```
$server->router->setPrefix("/your/custom/prefix");

```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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

1598d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/97861221?v=4)[Angus Dowling](/maintainers/angusdowlinghc)[@angusdowlinghc](https://github.com/angusdowlinghc)

---

Top Contributors

[![angusdowlinghc](https://avatars.githubusercontent.com/u/97861221?v=4)](https://github.com/angusdowlinghc "angusdowlinghc (7 commits)")

### Embed Badge

![Health badge](/badges/hc-rest-routes/health.svg)

```
[![Health](https://phpackages.com/badges/hc-rest-routes/health.svg)](https://phpackages.com/packages/hc-rest-routes)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M20](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k12](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)

PHPackages © 2026

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