# Implementation of PR-7 and PSR-15

This application template uses the httpsoft/http-message package, which is a lightweight, fast, high-performance, and strict implementation of PSR-7 and PSR-17.

The HttpSoft\Message package does not contain any additional functionality other than that defined in the PSR interfaces.

Two more packages are used that provide additional functionality:

Additional information:

# Middleware pipeline

For this application template and the HttpSoft\Basis microframework, using the middleware pipeline is a fundamental paradigm. The middleware pipeline works as follows.

  1. Adds a middleware are to the pipeline config/pipeline.php.
  2. The application runs processing the current HTTP request that implements the Psr\Http\Message\ServerRequestInterface.
  3. Using the httpsoft/http-runner package, the HTTP request object is processed by the previously set middleware in FIFO («first in, first out»).
  4. Depending on the result of processing the request, an HTTP response is returned that implement the Psr\Http\Message\ResponseInterface.

Middleware is any valid value that can be converted to an instance of the Psr\Http\Server\MiddlewareInterface, see HttpSoft\Runner\MiddlewareResolver.

The middleware whose work has an impact on other a middleware, such as the HttpSoft\ErrorHandler\ErrorHandlerMiddleware should be added first to the pipeline.

Additional information:

# Example of use

Creating an application object and setup middleware pipeline.

 * @var Psr\Container\ContainerInterface $container
 * @var Psr\Http\Server\MiddlewareInterface $adminMiddleware

$app = $container->get(HttpSoft\Basis\Application::class);

$app->pipe($adminMiddleware, '/admin');
// Any custom middleware.

Add routes.

use HttpSoft\Response\TextResponse;

$app->get('home', '/', fn => new TextResponse('Home'));
$app->get('about', '/about', fn => new TextResponse('About'));
$app->get('admin', '/admin', fn => new TextResponse('Admin'));
$app->get('admin.tasks', '/admin/tasks', fn => new TextResponse('Admin Tasks'));

Run application.

use HttpSoft\Message\Uri;

$request = HttpSoft\ServerRequest\ServerRequestCreator::create();

// Output result: 'Home'
$app->run($request->withUri(new Uri('/')));
// `$adminMiddleware` is not executed.

// Output result: 'About'
$app->run($request->withUri(new Uri('/about')));
// `$adminMiddleware` is not executed.

// Output result: 'Admin'
$app->run($request->withUri(new Uri('/admin')));
// `$adminMiddleware` is executed.

// Output result: 'Admin Tasks'
$app->run($request->withUri(new Uri('/admin/tasks')));
// `$adminMiddleware` is executed.

// Output result: '404 Not Found'
$app->run($request->withUri(new Uri('/blog')));
// `$adminMiddleware` is not executed.

Read more about routing here.