kingsoft/http
最新稳定版本:3.8.3
Composer 安装命令:
composer require kingsoft/http
包简介
Http Request/Response handler. It's a simple and easy to use library to handle http request and response.
README 文档
README
HTTP request, response, statuscodes
sample implementation
Sample implementation of the abstract Rest class under sample. Here a possible implementation:
use Kingsoft\Http\StatusCode; use Kingsoft\PersistRest\PersistRest; use Kingsoft\PersistRest\PersistRequest; use Kingsoft\Http\Response; class MyRest extends Rest { public function get(): { Response::sendStatusCode( StatusCode::OK ); Response::sendPayload( [ 'result'=> 'ok']); } public function post(): { Response::sendStatusCode( StatusCode::OK ); Response::sendPayload( [ 'result'=> 'ok']); } } try { $request = new Request( [ 'Test' ], // allowed endpoints // when using persist-db discover.php the result will give you a plugin list. "GET, POST", // allowed methods, (might change to a string array in the future) "http://client.example.com", // allowed origin ); $request->setLogger( LOG ); // add a (monolog) logger $api = new MyRest( $request, LOG ); // create the request handler $api->handleRequest(); // handle the request, which will send a well-formed HATEOAS response } catch ( Exception $e ) { // If things go terribly wrong, send an error to the client Response::sendError( $e->getMessage(), StatusCode::InternalServerError ); // By this time one or more errors have been logged already. }
统计信息
- 总下载量: 363
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-07-11