承接 patienceman/httprequestor 相关项目开发

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

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

patienceman/httprequestor

最新稳定版本:v1.0.0

Composer 安装命令:

composer require patienceman/httprequestor

包简介

HTTP Requestor: Package for a client request that supports you to make an external service request easily and with fast usage

README 文档

README

HTTP Requestor: Package for a client request that supports you to make an external service request easily and with fast usage.

Installation

Installing the package doesn't require much requirement except to paste the following command in the laravel terminal, and you're good to go.

  composer require patienceman/httprequestor

Usage

To use HTTP Requestor u need to call HttpRequest class, But before everything you need to publish the config file for "HTTP requestor", Just run!

php artisan vendor:publish --tag=HttpConfigs

Let's take the example with it and see the simplicity

  $http = HttpRequest::server('https://commandement.com');

So!, now you can make requests with all standard methods. There are two ways this package is useful, by requesting an access token to the server or by sending a normal request

let's take the example of requesting access token

  $http = HttpRequest::server('https://commandement.com');

  $http->buildHttpQuery([
      'grant_type' => 'client_credentials',
      'client_id' => config('services.custom.client_id'),
      'client_secret' => config('services.custom.client_secret'),
      'scope' => config('services.custom.scope)
  ]);

  return $http->requestToken('/oauth/token');

So now we are able to request an access tokens.

Let also take the example of a normally api request with standard HTTP methods

  $http = HttpRequest::server('https://commandement.com');

  $http->withHeaders([
      'Authorization' => $accessToken,
      'Accept' => 'application/json',
  ]);
  
  $http->withData([
    'name' => 'moses',
    'location' => 'mountain-sinai',
    'command' => 'navigate islaels'
  ]);
  
  $http->request('POST', '/api/sync-movement')

  return $http->then(function($response, $error) {
      return $response->last_update_at;
  });

Fantastic right! and super cool!

So now on Moses are able to make a super request to our commandment server!,

This package also contains the HttpResponse Helper class, which support your JSON response to remove all null value, on the go! To use it, u need just one class bash HttpResponse

let's take an example with it and see how it works!

  function httpJsonResponse(?string $message, $data = null, array $with, int $code = 200): JsonResponse {
      $response = HttpResponse::create(array_merge([
          'success' => ($code > 199 && $code < 300) ? true : false,
          'data' => $data,
          'message' => $message
      ], $with));

      return response()->json($response->extract(), $code);
  }

And whenever one of the passed parameters is null, the HttpResponse deletes it from the parameters, soon or later we're going to another way of making it optional.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固