saraf / async-request
reactphp/http 的包装器
0.0.1
2023-11-26 09:55 UTC
Requires
- php: >=8.1
- react/async: ^4 || ^3 || ^2
- react/http: >=1.6
- react/promise: >=2.10.0
This package is auto-updated.
Last update: 2024-09-24 15:04:54 UTC
README
它只是一个简单的 reactphp/http
库的包装器/辅助工具,可以创建更好的 开发者体验 和更快的开发。
简单设置
// initialize basic class $api = new \Saraf\AsyncRequestJson() $api->setConfig([ "baseURL" => "https://jsonplaceholder.typicode.com" ]); // It will return Promise $api->post("/todos", [ 'title' => 'learn async-request lib', 'isDone' => false ])->then(function ($response) { // $response contains result, status code, headers and body of that request });
自定义响应处理器
这种方式下,响应体将自动解码
$api->setResponseHandler(\Saraf\ResponseHandlers\HandlerEnum::Json);