承接 hasanparasteh/async-request 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hasanparasteh/async-request

最新稳定版本:0.1.5

Composer 安装命令:

composer require hasanparasteh/async-request

包简介

Use async curl in reactphp project as easy as possible

README 文档

README

This package will help you to send any request to any server in an asynchronous way! Just follow the instructions in order to install and setup the async curl package.

> composer require hasanparasteh/async-request

Quickstart Example

This is the simplest way to do a GET request. The results will be in a callable function which has 3 major data in it.

  1. result: bool=> represent that curl is successful or not
  2. code: int=> http status code
  3. body: array=> json decoded array which server returned
  4. error: string=> description of the curl error
$request = new AsyncRequest("https://reqres.in");
$request->get("/api/users", ["page" => 2])->then(function ($result) {
    if (!$result['result'])
        echo "Curl Error cause {$result['error']}";
    else
        switch ($result['code']) {
            case 200:
                echo "Server Response 200 With " . json_encode($result['body'], 128);
                break;
            case 400:
                echo "Server Response 400";
                break;
            case 500:
                echo "Server Response 500";
                break;
            // .. and any other response Code
        }
});

GET

if you need to pass any query params just sends the as an array to the second argument and if you need to add any header just pass it in the third argument as an array.

$request->get("endpoint")

POST

It's just like the GET request but it sends the paramethers as a json encoded raw!

$request->get("endpoint", ['paramName' => 'paramValue' ], ['headerName'=>'headerValue']);

PUT

It's exactly like the POST.

$request->put("endpoint")

PATCH

It's exactly like the POST.

$request->patch("endpoint")

DELETE

It's exactly like the POST.

$request->delete("endpoint")

统计信息

  • 总下载量: 3.2k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-12-11