cormy/server-request-handler

Common interfaces for PSR-7 server request handlers

0.1.0 2016-11-20 19:26 UTC

This package is not auto-updated.

Last update: 2024-12-21 20:41:37 UTC


README

SensioLabsInsight

🔩 Common interfaces for PSR-7 server request handlers

Install

composer require cormy/server-request-handler

Usage

The following snippet utilizes zend-diactoros:

composer require zendframework/zend-diactoros
use Cormy\Server\RequestHandlerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Response;

class RequestHandler implements RequestHandlerInterface
{
    /**
     * Process an incoming server request and return the response.
     *
     * @param ServerRequestInterface $request
     *
     * @return ResponseInterface
     */
    public function __invoke(ServerRequestInterface $request):ResponseInterface
    {
        $response = new Response();
        $response = $response->withHeader('content-type', 'application/json; charset=utf-8');
        // ...

        return $response;
    }
}

License

MIT © Michael Mayer