2017 © Pedro Peláez
 

library php-api-client

PHP lib for making API calls

image

demi/php-api-client

PHP lib for making API calls

  • Thursday, February 1, 2018
  • by demi
  • Repository
  • 1 Watchers
  • 1 Stars
  • 146 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 0 % Grown

The README.md

php-api-client

PHP lib for making API calls, (*1)

Installation

Run:, (*2)

composer require "demi/php-api-client" "~1.0"

Usage

As client

<?php

$client = new \demi\api\Client([
    'baseUri' => 'https://google.com/api/',
    'timeout' => 30,
    'defaultHeaders' => [],
    'defaultQueryParams' => [],
]);

// Simple example: get index page content
$content = $client->get('http://example.com/index.php')->send()->body();

// Make request to baseUri + 'users'
$request = $client->post('users')
    ->setQueryParam('id', 123) // Single param
    ->setQueryParam(['name' => 'Jack', 'company' => 'Google']) // Params array
    ->setPostParam('password', '12345') // Single POST param
    ->setPostParam(['email' => 'example@com', 'location' => 'London']) // POST params array
    ->setHeaderParam('Connection', 'Keep-Alive') // Header value
    ->setHeaderParam(['Accept' => 'image/gif', 'Some-Custom' => 'value']); // Headers array

// Resets
$request->queryParams = []; // Reset query params
$request->formParams = []; // Reset post params
$request->headerParams = []; // Reser headers

// Submit request and get Response object
$response = $request->send();

Without client instance

<?php

// Static calls
$response = \demi\api\ApiRequest::get('http://example.com/index.php');
$response = \demi\api\ApiRequest::post('http://example.com/index.php');
$response = \demi\api\ApiRequest::put('http://example.com/index.php');
$response = \demi\api\ApiRequest::delete('http://example.com/index.php');

Response info

$statusCode = $response->statusCode(); // Response code: 200, 201, 204, etc...
$bodyText = $response->body(); // Content
$bodyJson = $response->json(); // Json decoded content
$headerParams = $response->headers(); // Headers array
$headerValue = $response->headerValue('Encoding', 'Default value'); // Some header value

The Versions

01/02 2018

dev-master

9999999-dev https://github.com/demisang/php-api-client#readme

PHP lib for making API calls

  Sources   Download

GNU GPL-3.0-or-later

The Requires

  • php >=5.3.0

 

api php client calls

24/08 2016

1.1.2

1.1.2.0 https://github.com/demisang/php-api-client#readme

PHP lib for making API calls

  Sources   Download

GNU

The Requires

  • php >=5.3.0

 

api php client calls

07/08 2016

1.1.1

1.1.1.0 https://github.com/demisang/php-api-client#readme

PHP lib for making API calls

  Sources   Download

GNU

The Requires

  • php >=5.3.0

 

api php client calls

02/07 2016

1.1.0

1.1.0.0 https://github.com/demisang/php-api-client#readme

PHP lib for making API calls

  Sources   Download

GNU

The Requires

  • php >=5.3.0

 

api php client calls

19/06 2016

1.0.5

1.0.5.0 https://github.com/demisang/php-api-client#readme

PHP lib for making API calls

  Sources   Download

GNU

The Requires

  • php >=5.3.0

 

api php client calls

06/06 2016

1.0.4

1.0.4.0 https://github.com/demisang/php-api-client#readme

PHP lib for making API calls

  Sources   Download

GNU

The Requires

  • php >=5.3.0

 

api php client calls

06/06 2016

1.0.3

1.0.3.0 https://github.com/demisang/php-api-client#readme

PHP lib for making API calls

  Sources   Download

GNU

The Requires

  • php >=5.3.0

 

api php client calls

06/06 2016

1.0.2

1.0.2.0 https://github.com/demisang/php-api-client#readme

PHP lib for making API calls

  Sources   Download

GNU

The Requires

  • php >=5.3.0

 

api php client calls

06/06 2016

1.0.1

1.0.1.0 https://github.com/demisang/php-api-client#readme

PHP lib for making API calls

  Sources   Download

GNU

The Requires

  • php >=5.3.0

 

api php client calls

06/06 2016

1.0.0

1.0.0.0 https://github.com/demisang/php-api-client#readme

PHP lib for making API calls

  Sources   Download

GNU

The Requires

  • php >=5.3.0

 

api php client calls