PHP code example of patienceman / httprequestor

1. Go to this page and download the library: Download patienceman/httprequestor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

patienceman / httprequestor example snippets


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

  $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');

  $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;
  });
 
  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);
  }
bash 
php artisan vendor:publish --tag=HttpConfigs