kuick/http

Kuick HTTP is a slim PSR-15 implementation

v1.0.1 2025-01-22 09:37 UTC

This package is auto-updated.

Last update: 2025-01-22 09:37:51 UTC


README

Latest Version PHP Total Downloads GitHub Actions CI codecov Software License

Kuick PSR-15 implementation of HTTP Server Request Handlers

Key features

  1. PSR-15 (https://www.php-fig.org/psr/psr-15/) implementation
  2. PSR-7 Response Emitter
  3. PSR-7 Response implementation with JsonResponse extension
  4. Handful HTTP error based Exception collection

Examples

  1. Using RequestHandler
<?php

use Kuick\Http\RequestHandler;
use Kuick\Http\Server\ExceptionJsonRequestHandler;
use Nyholm\Psr7\ServerRequest;
use Psr\Log\NullLogger;

$request = new ServerRequest('GET', '/something');

// request handler needs a fallback, exception handling handler
$exceptionHandler = new ExceptionJsonRequestHandler(new NullLogger());

$handler = new RequestHandler($exceptionHandler);
$response = $handler->handle($request);

// 404, the response implements PSR-7 ResponseInterface
echo $response->getStatusCode();

  1. Emitting PSR-7 response
<?php

use Kuick\Http\Message\JsonResponse;
use Kuick\Http\Server\ResponseEmitter;

$emitter = new ResponseEmitter();
$response = new JsonResponse(['message' => 'test']);
$emitter->emitResponse($response);