kingsoft / http
Http Request/Response handler. It's a simple and easy to use library to handle http request and response.
3.7.13
2024-11-13 08:57 UTC
Requires
- psr/log: ^3.0
- dev-main
- 3.7.13
- 3.7.12
- 3.7.11
- 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/issue77
This package is auto-updated.
Last update: 2024-11-13 09:23:11 UTC
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. }