kuick / http
Kuick HTTP is a slim PSR-15 implementation
Installs: 1 652
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=8.2.0
- nyholm/psr7: ^1.8
- nyholm/psr7-server: ^1.1
- psr/http-server-handler: ^1.0.2
- psr/http-server-middleware: ^1.0.2
- psr/log: ^3.0
Requires (Dev)
- kuick/qa-toolkit: ^1.0
Provides
README
Kuick PSR-15 implementation of HTTP Server Request Handlers
Key features
- PSR-15 (https://www.php-fig.org/psr/psr-15/) Request Handler implementation (Stack with a fallback)
- PSR-7 Response Emitter
- PSR-7 Response implementation with JsonResponse extension
Examples
- 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();
- 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);