kuick/http

Kuick HTTP is a slim PSR-15 implementation

v2.0.0 2025-01-26 21:45 UTC

This package is auto-updated.

Last update: 2025-01-27 13:48:11 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/) Request Handler implementation (Stack with a fallback)
  2. PSR-7 Response Emitter
  3. PSR-7 Response implementation with JsonResponse extension

Examples

  1. Using RequestHandler
<?php

use Kuick\Http\StackRequestHandler;
use Kuick\Http\Server\JsonNotFoundRequestHandler;
use Nyholm\Psr7\ServerRequest;

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

// handler needs a fallback handler, using JSON one
$handler = new StackRequestHandler(new JsonNotFoundRequestHandler());
// middlewares
// $handler->addMiddleware($someMiddleware);
// $handler->addMiddleware($anotherMiddleware);
$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);