tiny-blocks / http
HTTP协议的常见实现。
3.1.0
2024-03-11 14:23 UTC
Requires
- php: ^8.2
- ext-mbstring: *
- psr/http-message: ^1.1
- tiny-blocks/serializer: ^3.0
Requires (Dev)
- infection/infection: ^0.27
- phpmd/phpmd: ^2.15
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.8
Suggests
- ext-mbstring: Provides multibyte-specific string functions that help us deal with multibyte encodings in PHP.
README
概览
HTTP协议的常见实现。
安装
composer require tiny-blocks/http
如何使用
该库公开了HTTP协议的具体实现,例如状态码、方法等。
使用HttpCode
该库通过HttpCode
枚举公开了具体实现。您可以获取状态码及其对应的消息。
$httpCode = HttpCode::CREATED; $httpCode->name; # CREATED $httpCode->value; # 201 $httpCode->message(); # 201 Created
使用HttpMethod
该库通过HttpMethod
枚举公开了具体实现。您可以获取一组HTTP方法。
$method = HttpMethod::GET; $method->name; # GET $method->value; # GET
使用HttpResponse
该库通过HttpResponse
类公开了HTTP响应的具体实现。响应类型为ResponseInterface,根据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采用MIT许可证。
贡献
请遵循贡献指南以贡献到项目。