Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/pollen-solutions/routing

Pollen Solutions - Routing Component - HTTP request mapping and HTTP response resolution
https://github.com/pollen-solutions/routing

Last synced: 6 days ago
JSON representation

Pollen Solutions - Routing Component - HTTP request mapping and HTTP response resolution

Awesome Lists containing this project

README

        

# Routing Component

[![Latest Stable Version](https://img.shields.io/packagist/v/pollen-solutions/routing.svg?style=for-the-badge)](https://packagist.org/packages/pollen-solutions/routing)
[![MIT Licensed](https://img.shields.io/badge/license-MIT-green?style=for-the-badge)](LICENSE.md)
[![PHP Supported Versions](https://img.shields.io/badge/PHP->=7.4-8892BF?style=for-the-badge&logo=php)](https://www.php.net/supported-versions.php)

Pollen Solutions **Routing** Component provide a layer of HTTP request mapping and HTTP response resolution.

## Installation

```bash
composer require pollen-solutions/routing
```

## Basic Usage

```php
map('GET', '/', static function (): ResponseInterface {
return new Response('

Hello, World!

');
});

$router->map('GET', '/phpinfo', static function () {
ob_start();
phpinfo();
return new Response(ob_get_clean());
});

// Setting Handle Request (optional)
$psrRequest = Request::createFromGlobals()->psr();

// Map a Fallback Route (optional)
$router->setFallback(function () {
return new Response('

404 - Page not found !

', 404);
});

// Catch HTTP Response
$response = $router->handle($psrRequest);

// Send the response to the browser
$router->send($response);

// Trigger the terminate event
$router->terminate($psrRequest, $response);
```