kingsoft /
http
Http 请求/响应处理器。这是一个简单易用的库,用于处理 Http 请求和响应。
3.7.10
2024-09-09 12:03 UTC
Requires
- psr/log: ^3.0
- dev-main
- 3.7.10
- 3.7.9
- 3.7.8
- 3.7.7
- 3.7.6
- 3.7.5
- 3.7.1
- 3.7.0
- 3.6.2
- 3.6.1
- 3.6.0
- 3.5.8
- 3.5.7
- 3.5.6
- 3.5.5
- 3.5.4
- 3.5.3
- 3.5.2
- 3.5.1
- 3.5.0
- 3.0.1
- 3.0.0
- 2.7.2
- 2.7.1
- 2.7.0
- 2.6.15
- 2.6.14
- 2.6.13
- 2.6.12
- 2.6.11
- 2.6.10
- 2.6.9
- 2.6.8
- 2.6.7
- 2.6.6
- 2.6.5
- 2.6.4
- 2.6.3
- 2.6.2
- 2.6.1
- 2.6.0
- 2.5.0
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 1.1.0
- 1.0.0
- dev-theking2/issue73
This package is auto-updated.
Last update: 2024-09-09 12:04:46 UTC
README
HTTP 请求,响应,状态码
示例实现
在 sample 目录下,抽象 Rest 类的示例实现。这里是一个可能的实现方法
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. }