2017 © Pedro Peláez
 

library http-api-gluer

image

fenzland/http-api-gluer

  • Monday, March 26, 2018
  • by Fenzland
  • Repository
  • 1 Watchers
  • 0 Stars
  • 16 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 60 % Grown

The README.md

HTTP API Gluer

A library for calling HTTP API, and avoid hard code about details of specific API., (*1)

Usage

composer require fenzland/http-api-gluer

Create instance of Gluer., (*2)

use Fenzland\HttpApiGluer\Gluer;
use Fenzland\DataParser\Transformer;

$gluer= new Gluer(
    'https://url'           // URL of API.
,
    'POST'                  // Method of API.
,
    $request_transformer    // instance of Transformer.
,
    $response_transformer   // instance of Transformer.
,
    'application/json'      // content type of request
,
    'application/json'      // content type of response (optional if same with content type of request)
);

// or

$gluer= Gluer::make_(
    'https://url/{path_param}'
,
    'POST'
,
    $request_transformer_meta    // meta array of Transformer.
,
    $response_transformer_meta   // meta array of Transformer.
,
    'application/json'
);

Call api., (*3)

$result= $gluer->call( $data );

Account Types

Built-in supported

  • application/octet-stream
  • application/php-serialized
  • application/json
  • application/x-www-form-urlencoded

Extending

use Fenzland\HttpApiGluer\serializers\ASerializer

class CustomSerializer extends ASerializer
{
    public function encode( $data ):string
    {
        # ...
    }

    public function decode( string$encoded )
    {
        # ...
    }
}

Gluer::registerSerializer_( 'custom/mime', CustomSerializer::class );
// or
Gluer::registerSerializer_( 'custom/mime', new CustomSerializer );

About Transformer

Preliminary: fenzland/data-parser, (*4)

Request Transformer

[
    'path'=> ...,     // parameters in path example: https://github.com/{name}/{repo}
    'query'=> ...,    // parameters in url query example: ?key0=value0&key1=value1
    'headers'=> ...,  // parameters in header
    'body'=> ...,     // parameters or data in body
];

Response Transformer

[
    "foo_in_header"=> [
        'type'=> 'value',
        'keys'=> [ 'headers', "foo", ],
    ],
    "bar_in_body"=> [
        'type'=> 'value',
        'keys'=> [ 'body', "bar", "baz", ],
    ],
];

The Versions

26/03 2018

dev-test

dev-test

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fenz

26/03 2018

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

by Fenz

26/03 2018

0.2.0

0.2.0.0

  Sources   Download

MIT

The Requires

 

by Fenz

23/03 2018

0.1.0

0.1.0.0

  Sources   Download

MIT

The Requires

 

by Fenz

23/03 2018

dev-dev

dev-dev

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fenz