ckunkle / httpassage
A simple, flexible library for routing and processing PSR-7 messages
1.0.1
2021-03-02 12:46 UTC
Requires
- php: >=7
- altorouter/altorouter: ^2
- psr/http-message: ^1.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- guzzlehttp/psr7: ^1.7
- phpunit/phpunit: ^4
This package is auto-updated.
Last update: 2024-04-11 20:43:11 UTC
README
A simple, flexible library for routing and processing PSR-7 HTTP messages.
Features
- HTTP request routing built on top of AltoRouter
- Compatible with any PSR-7 implementation
- Customizable callback system for processing requests and responses
- Compatible with PSR-15 middleware and request handlers out of the box
Installation
composer require ckunkle/httpassage
Quickstart
This example uses guzzlehttp/psr7
for the PSR-7 implementation, but any PSR-7 implementation will work here.
<?php require __DIR__ . "/vendor/autoload.php"; /** * Create an instance of Context by passing a PSR-7 ServerRequest * and a PSR-7 response to the constructor */ new \HTTPassage\Context( \GuzzleHttp\Psr7\ServerRequest::fromGlobals(), new \GuzzleHttp\Psr7\Response() ); /** * Create a Router instance and map some routes */ $router = new \HTTPassage\Router(); $router->get("/my/example/[a:route]", function($context) { $route = $context->getRouteParamater("route"); $context->getResponse()->getBody()->write("You have reached $route!"); return $context; }); /** * Route the Context */ $context = $router->route($context);