PHPackages                             rockberpro/rosa-router - 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. rockberpro/rosa-router

ActiveLibrary[API Development](/categories/api)

rockberpro/rosa-router
======================

Smart REST router for PHP

v2.6.1(1w ago)0123MITPHPPHP &gt;=8.4CI passing

Since Oct 8Pushed 1w ago1 watchersCompare

[ Source](https://github.com/rockberpro/rosa-router)[ Packagist](https://packagist.org/packages/rockberpro/rosa-router)[ RSS](/packages/rockberpro-rosa-router/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (12)Versions (117)Used By (0)

 [![ROSA Router — PHP REST API Router](resources/img/rosa-router-logo--cropped.png)](resources/img/rosa-router-logo--cropped.png)

 **A smart, lightweight and fast REST router for PHP.**

 [![Tests](https://github.com/rockberpro/rosa-router/actions/workflows/tests.yml/badge.svg)](https://github.com/rockberpro/rosa-router/actions/workflows/tests.yml) [![Latest Version](https://camo.githubusercontent.com/2d0d12b190dec06f6d9e941649bdbc605eb27fefc84e500a1e1784752e333695/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f636b62657270726f2f726f73612d726f757465722e737667)](https://packagist.org/packages/rockberpro/rosa-router) [![PHP Version](https://camo.githubusercontent.com/8aa41ea7f8168ba0065b3d53aa343b06686652db1bc5b5af410cf795b633c68f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344382e302d3737374242343f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://www.php.net/) [![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE) [![PSR-4](https://camo.githubusercontent.com/2167b0d01cf765bd759e628ac2fd9aef376759de196ca474a7bb60ef51f239fd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d2d342d6175746f6c6f61642d626c75652e737667)](https://camo.githubusercontent.com/2167b0d01cf765bd759e628ac2fd9aef376759de196ca474a7bb60ef51f239fd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d2d342d6175746f6c6f61642d626c75652e737667)

---

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

[](#table-of-contents)

- [Overview](#overview)
- [Why ROSA Router?](#why-rosa-router)
- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Quick Start](#quick-start)
- [Usage](#usage)
- [Authentication](#authentication)
- [Logging](#logging)
- [Testing](#testing)
- [License](#license)

Overview
--------

[](#overview)

**ROSA Router** is a lightweight and efficient REST API engine built with PHP. It handles incoming HTTP requests and routes them to the appropriate controllers or actions based on your defined endpoints. With a focus on **simplicity** and **performance**, ROSA Router lets you build and deploy RESTful web services quickly — in both stateless and stateful (long-running server) modes.

Why ROSA Router?
----------------

[](#why-rosa-router)

Most PHP routers force a choice up front: the classic **stateless** model — where the framework boots from scratch on every request — or a **stateful**, long-running server for lower latency. ROSA Router runs the *same* route definitions in **both modes**, so you can start simple on a shared host and later switch to a persistent [ReactPHP](https://reactphp.org/) server by changing a single flag — no rewrite.

On top of that it stays **dependency-light and explicit**: a clean routing syntax, first-class middleware, and **authentication built in** (JWT and API keys), without pulling in a full framework.

Features
--------

[](#features)

- 🚀 **Easy routing** — Define routes for your REST API with a clean, expressive syntax.
- 🔀 **Full HTTP method support** — `GET`, `POST`, `PUT`, `PATCH` and `DELETE`.
- 🧩 **Route groups &amp; prefixes** — Organize routes with prefixes, nesting and namespaces.
- 🛡️ **Middleware** — Attach middleware to single routes or whole groups.
- 🔐 **Built-in authentication** — JWT and API key strategies out of the box.
- 📝 **Request logging** — Opt-in per-route logging to file or database.
- ⚡ **Stateless or stateful** — Run on a classic web server or as a long-running ReactPHP server.
- 🪶 **Lightweight &amp; fast** — Minimal overhead, optimized for performance.
- 🧯 **Built-in error handling** — Gracefully manage exceptions and invalid requests.

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

[](#requirements)

- PHP **8.0** or higher
- [Composer](https://getcomposer.org/)
- Extensions: `ext-json`, `ext-pdo`

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

[](#installation)

```
composer require rockberpro/rosa-router
```

Configuration
-------------

[](#configuration)

ROSA Router is configured through environment variables loaded at bootstrap. Copy the example file and adjust it for your environment:

```
cp .env.example .env
```

`Bootstrap::setup()` loads the configuration automatically. You can point it at a custom path — both `.env` and `.ini` formats are supported:

```
Bootstrap::setup();               // loads ./.env
Bootstrap::setup('config/.env');  // custom path
Bootstrap::setup('config/.ini');  // INI format
```

VariableDescriptionExample`API_NAME`Application name`rosa-api``API_DEBUG`Verbose error output`false``API_LOGS` / `API_LOGS_DB`Request-log destination — file / database (see [Logging](#logging))`true` / `false``API_ALLOW_ORIGIN`CORS allowed origin`*``API_SERVER_ADDRESS` / `API_SERVER_PORT`Address &amp; port for stateful mode`0.0.0.0` / `8081``API_AUTH_METHOD`Authentication strategy — `JWT` or `KEY``JWT``JWT_ISSUER` / `JWT_SUBJECT` / `JWT_SECRET`JWT signing settings—`API_DB_*`Database connection (host, port, user, pass, name, type)`pgsql`How It Works
------------

[](#how-it-works)

ROSA Router listens for HTTP requests and maps them to the correct route handler based on the request's method and URI. It supports both static and dynamic routes and is fully customizable to fit different project needs.

Quick Start
-----------

[](#quick-start)

### Stateless mode (web server)

[](#stateless-mode-web-server)

```
