PHPackages                             phpnomad/fastroute-rest-integration - 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. phpnomad/fastroute-rest-integration

ActiveLibrary[API Development](/categories/api)

phpnomad/fastroute-rest-integration
===================================

description

1.0.7(3mo ago)058[2 PRs](https://github.com/phpnomad/fastroute-integration/pulls)1MITPHPCI passing

Since Dec 18Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/phpnomad/fastroute-integration)[ Packagist](https://packagist.org/packages/phpnomad/fastroute-rest-integration)[ RSS](/packages/phpnomad-fastroute-rest-integration/feed)WikiDiscussions main Synced today

READMEChangelog (7)Dependencies (12)Versions (12)Used By (1)

phpnomad/fastroute-rest-integration
===================================

[](#phpnomadfastroute-rest-integration)

[![Latest Version](https://camo.githubusercontent.com/b6aafedab09e033459be5784cd2243ee2bcbb43d4f9c91927c6a845ddba9060d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068706e6f6d61642f66617374726f7574652d726573742d696e746567726174696f6e2e737667)](https://packagist.org/packages/phpnomad/fastroute-rest-integration)[![Total Downloads](https://camo.githubusercontent.com/c60efa39805c54cde0be59b96014dbe2069d7ed57368d20e4420ddda0311b0cb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068706e6f6d61642f66617374726f7574652d726573742d696e746567726174696f6e2e737667)](https://packagist.org/packages/phpnomad/fastroute-rest-integration)[![PHP Version](https://camo.githubusercontent.com/627514e5ef458a45489cc24366910cc7651ced1ffa2d0f361e216e712a4f760c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7068706e6f6d61642f66617374726f7574652d726573742d696e746567726174696f6e2e737667)](https://packagist.org/packages/phpnomad/fastroute-rest-integration)[![License](https://camo.githubusercontent.com/180736f938cd8eb5341b0422530d459493de5900e292dd3be5586d54bcba5fe4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7068706e6f6d61642f66617374726f7574652d726573742d696e746567726174696f6e2e737667)](https://packagist.org/packages/phpnomad/fastroute-rest-integration)

Integrates [nikic/fast-route](https://github.com/nikic/FastRoute) with `phpnomad/rest` as a runtime REST router. This is the standard non-WordPress `RestStrategy` for PHPNomad applications. It hosts controllers defined against `phpnomad/rest` inside a FastRoute dispatcher, binds PHP-superglobal-backed `Request` and `Response` implementations for `phpnomad/http`, and dispatches routes in response to a `RequestInitiated` event.

Installation
------------

[](#installation)

The Composer package name is `phpnomad/fastroute-rest-integration`, even though the repository is named `fastroute-integration`.

```
composer require phpnomad/fastroute-rest-integration
```

What This Provides
------------------

[](#what-this-provides)

- `RestStrategy` implementing `PHPNomad\Rest\Interfaces\RestStrategy`, backed by `nikic/fast-route`. It registers controllers as FastRoute handlers, runs any middleware declared on the controller, and runs interceptors after the response is built.
- `Request` and `Response` classes that implement the `phpnomad/http` interfaces. `Request` reads from `$_SERVER`, `$_REQUEST`, and `php://input`. `Response` is an in-memory status, headers, and body holder with JSON and error helpers.
- `RestInitializer`, a loader initializer that registers the bindings above and attaches a `DispatchRequest` listener to the `RequestInitiated` event.

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

[](#requirements)

- [`phpnomad/rest`](https://packagist.org/packages/phpnomad/rest), the abstraction this integration implements
- [`phpnomad/loader`](https://packagist.org/packages/phpnomad/loader), to run the initializer
- [`nikic/fast-route`](https://github.com/nikic/FastRoute), pulled in automatically by Composer

Usage
-----

[](#usage)

Add `RestInitializer` to the initializer list you pass to the `Bootstrapper`. Once `load()` runs, your controllers are routed through FastRoute and dispatched when a `RequestInitiated` event fires.

```
