psr/http-server-handler
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The psr/http-server-handler is an interface rather than an implementation of its own. It defines common methods that are required to build a server-side request handler in PHP, as specified by PSR-15 HTTP Server Request Handlers. HTTP server-side request handlers are an integral part of any middleware, and this interface helps to standardize the way these handlers are implemented in PHP.
To use psr/http-server-handler, you need to implement the RequestHandlerInterface
in your PHP class. The interface specifies a single method called handle()
, which you will need to define in your class. Here's a basic example of what this might look like:
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
class YourRequestHandler implements RequestHandlerInterface
{
public function handle(ServerRequestInterface $request): ResponseInterface
{
// Your code goes here.
}
}
In this code, we create a class called YourRequestHandler
that implements RequestHandlerInterface
. We then define the handle()
method, which is expected to take a ServerRequestInterface
object and return a ResponseInterface
object.
Documentation for the psr/http-server-handler is primarily located on the official PHP-FIG website. Specifically, you can find more information about PSR-15, which the psr/http-server-handler is based on, at https://www.php-fig.org/psr/psr-15/. For more in-depth usage and implementation examples, you can check various packages listed under implementations on Packagist at https://packagist.org/providers/psr/http-server-handler-implementation.