2017 © Pedro Peláez
 

library php-api-client

Generic PHP API client for Bokbasen's API

image

bokbasen/php-api-client

Generic PHP API client for Bokbasen's API

  • Wednesday, August 30, 2017
  • by bokbasen
  • Repository
  • 4 Watchers
  • 0 Stars
  • 518 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 13 % Grown

The README.md

php-api-client

Build Status Code Coverage Scrutinizer Code Quality, (*1)

Click here if you're looking for documentation to version 1.*, (*2)

Generic API client for use against all Bokbasen APIs where no spesific SDK is implemented that require authetication., (*3)

The HTTP client is simple in use and you must implement API spesific functionality yourself. But it provides a standard interface to do request against Bokbasen APIs and allow you to use the Login SDK handling any complexity related to authentication., (*4)

First create a Login object see php-sdk-auth for details, (*5)

Installation

We are using HttpClientDiscovery so you'll need to require a PSR-7 compatible implementation, e.g.;, (*6)

$ composer require php-http/guzzle6-adapter

Then add our package:, (*7)

$ composer require bokbasen/php-api-client

Usage

use Bokbasen\Auth\Login;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

try {
    /* This example is using a file cache for the TGT, you can replace this with any PSR-6 
        compatible cache. Always using caching in production to avoid performance penalty of 
        creating and deleting tokens.
    */
    $cache = new FilesystemAdapter();
    $login = new Login('username', 'password', Login::URL_PROD, $cache);
} catch(\Throwable $e) {
    // error handling
}
use Bokbasen\ApiClient\Client;
use Bokbasen\ApiClient\HttpRequestOptions;
use Bokbasen\ApiClient\Exceptions\BokbasenApiClientException;

try {
    /* Pass the base URL of the API you are interacting with. You can also pass a logger 
        and a custom http client. Any request made through the API returns an instance 
        of \Psr\Http\Message\ResponseInterface.  All of these API calls will include the 
        necessary authentication headers.
    */
    $client = new Client($login, 'https://loan.api.boknett.no');

    // Execute get request, it is recommended to explicitly set accept parameter
    $headers = ['Accept' => HttpRequestOptions::CONTENT_TYPE_JSON];
    $response = $client->get('/path', $headers);

    // Execute POST request with json data
    $response = $client->postJson('/path', $body, $headers);

    // Execute POST request 
    $response = $client->post('/path', $body, $headers);

    // Execute PUT request
    $response = $client->put('/path', $body, $headers);

    // Execute PATCH request
    $response = $client->patch('/path', $body, $headers);
} catch(BokbasenApiClientException $e){
    //error handling
}

Tests

$ ./vendor/bin/phpunit

The Versions

30/08 2017

dev-master

9999999-dev https://github.com/Bokbasen/php-api-client

Generic PHP API client for Bokbasen's API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ketil Stadskleiv

26/06 2017

v1.0.1

1.0.1.0 https://github.com/Bokbasen/php-api-client

Generic PHP API client for Bokbasen's API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ketil Stadskleiv

26/06 2017

v1.0

1.0.0.0 https://github.com/Bokbasen/php-api-client

Generic PHP API client for Bokbasen's API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ketil Stadskleiv