Common implementations for HTTP protocol.
composer require tiny-blocks/http
The library exposes concrete implementations for the HTTP protocol, such as status codes, methods, etc.
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
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
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}
Http is licensed under MIT.
Please follow the contributing guidelines to contribute to the project.