PHP code example of fenzland / http-api-gluer

1. Go to this page and download the library: Download fenzland/http-api-gluer 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/ */

    

fenzland / http-api-gluer example snippets


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


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

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

[
	'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
];

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