tiny-blocks / http
Common implementations for HTTP protocol.
Installs: 17 609
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- ext-mbstring: *
- psr/http-message: ^1.1
- tiny-blocks/serializer: ^3
Requires (Dev)
- infection/infection: ^0.29
- phpmd/phpmd: ^2.15
- phpstan/phpstan: ^1
- phpunit/phpunit: ^11
- squizlabs/php_codesniffer: ^3.10
Suggests
- ext-mbstring: Provides multibyte-specific string functions that help us deal with multibyte encodings in PHP.
README
Overview
Common implementations for HTTP protocol.
Installation
composer require tiny-blocks/http
How to use
The library exposes concrete implementations for the HTTP protocol, such as status codes, methods, etc.
Using the HttpCode
The library exposes a concrete implementation through the HttpCode
enum. You can get the status codes, and their
corresponding messages.
$httpCode = HttpCode::CREATED; $httpCode->name; # CREATED $httpCode->value; # 201 $httpCode->message(); # 201 Created
Using the HttpMethod
The library exposes a concrete implementation via the HttpMethod
enum. You can get a set of HTTP methods.
$method = HttpMethod::GET; $method->name; # GET $method->value; # GET
Using the HttpResponse
The library exposes a concrete implementation for HTTP responses via the HttpResponse
class. Responses are of the
ResponseInterface type, according to
the specifications defined in PSR-7.
$data = new Xyz(value: 10); $response = HttpResponse::ok(data: $data); $response->getStatusCode(); # 200 $response->getReasonPhrase(); # 200 OK $response->getBody()->getContents(); # {"value":10}
License
Http is licensed under MIT.
Contributing
Please follow the contributing guidelines to contribute to the project.