Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/httpsoft/http-runner
Running PSR-7 components and building PSR-15 middleware pipelines
https://github.com/httpsoft/http-runner
http http-middleware middleware-pipeline php psr-15 psr-7
Last synced: 3 months ago
JSON representation
Running PSR-7 components and building PSR-15 middleware pipelines
- Host: GitHub
- URL: https://github.com/httpsoft/http-runner
- Owner: httpsoft
- License: mit
- Created: 2020-09-01T15:08:16.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-05-05T21:48:33.000Z (over 1 year ago)
- Last Synced: 2024-07-17T19:15:13.900Z (4 months ago)
- Topics: http, http-middleware, middleware-pipeline, php, psr-15, psr-7
- Language: PHP
- Homepage: https://httpsoft.org/docs/runner
- Size: 48.8 KB
- Stars: 10
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
- awesome-psr15-middlewares - httpsoft/http-runner - Running PSR-7 components and building PSR-15 middleware pipelines. (Packages / Dispatcher)
README
# HTTP Runner
[![License](https://poser.pugx.org/httpsoft/http-runner/license)](https://packagist.org/packages/httpsoft/http-runner)
[![Latest Stable Version](https://poser.pugx.org/httpsoft/http-runner/v)](https://packagist.org/packages/httpsoft/http-runner)
[![Total Downloads](https://poser.pugx.org/httpsoft/http-runner/downloads)](https://packagist.org/packages/httpsoft/http-runner)
[![GitHub Build Status](https://github.com/httpsoft/http-runner/workflows/build/badge.svg)](https://github.com/httpsoft/http-runner/actions)
[![GitHub Static Analysis Status](https://github.com/httpsoft/http-runner/workflows/static/badge.svg)](https://github.com/httpsoft/http-runner/actions)
[![Scrutinizer Code Coverage](https://scrutinizer-ci.com/g/httpsoft/http-runner/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/httpsoft/http-runner/?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/httpsoft/http-runner/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/httpsoft/http-runner/?branch=master)This package is responsible for running [PSR-7](https://github.com/php-fig/http-message) components and building [PSR-15](https://github.com/php-fig/http-factory) middleware pipelines.
## Documentation
* [In English language](https://httpsoft.org/docs/runner).
* [In Russian language](https://httpsoft.org/ru/docs/runner).## Installation
This package requires PHP version 7.4 or later.
```
composer require httpsoft/http-runner
```## Usage
```php
use HttpSoft\Runner\MiddlewarePipeline;
use HttpSoft\Runner\MiddlewareResolver;
use HttpSoft\Runner\ServerRequestRunner;
use Psr\Http\Message\ResponseInterface;/**
* @var Psr\Http\Message\ServerRequestInterface $request
* @var Psr\Http\Server\RequestHandlerInterface $handler
* @var Psr\Http\Server\MiddlewareInterface $siteMiddleware
* @var Psr\Http\Server\MiddlewareInterface $userMiddleware
*/// Basic usage
$runner = new ServerRequestRunner();
$runner->run($request, $handler);// Using `MiddlewarePipeline`
$pipeline = new MiddlewarePipeline();
$pipeline->pipe($siteMiddleware);
$pipeline->pipe($userMiddleware, '/user');$runner = new ServerRequestRunner($pipeline);
$runner->run($request, $handler);// Using `MiddlewareResolver`
$resolver = new MiddlewareResolver();
$handlerMiddleware = $resolver->resolve(function (): ResponseInterface {
$response = new HttpSoft\Message\Response();
$response->getBody()->write('Hello world!');
return $response;
});$pipeline = new MiddlewarePipeline();
$pipeline->pipe($siteMiddleware);
$pipeline->pipe($userMiddleware, '/user');
$pipeline->pipe($handlerMiddleware);$runner = new ServerRequestRunner($pipeline);
$runner->run($request); // Output result: 'Hello world!'
```