2017 © Pedro Peláez
 

library restapi

Core provides a unified interface for building API Clients

image

sapistudio/restapi

Core provides a unified interface for building API Clients

  • Wednesday, June 20, 2018
  • by maharbig
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 150 % Grown

The README.md

provides a unified interface for building API Clients, (*1)

first create your client class, (*2)

use SapiStudio\RestApi\AbstractHttpClient;

/**
 * Class HttpClient.
 */
class HttpClient extends AbstractHttpClient
{
    protected $headers = [
          any custom header as array
    ];

    protected $requestModifiers = [RequestModifier::class];

    protected $responseFormat = 'xml json or txt';

    protected function buildRequestUri($baseUri,$path=false)
    {
        format your own custom request url
    }
}

Next create your modifier, (*3)

use SapiStudio\RestApi\Request\Modifier;

class RequestModifier extends Modifier
{
    public function apply()
    {
        $this->httpClient->setOption('base_uri', $this->httpClient->getConfig('your config key set on init'));//this is a required parameter,the base uri of the api call
        $this->httpClient->addFormParameter('apikey', $this->httpClient->getConfig('apikey'));//if you set an api key in config,you can use it here
        return $this->httpClient;
    }
}

And finally , your api class, (*4)

use SapiStudio\RestApi\AbstractApi;

class MyApi extends AbstractApi
{
    public function myapiFunction()
    {
        $this->addFormParameter('apifunc',$functionName);
        return $this->post(true,$parameters);
        return $this->get(true,$parameters);
    }
}

And now to use it, (*5)

$class      = new HttpClient();
$class->setConfig(['key'        => value]);
$apicall = $class->api('MyApi')->myapiFunction();

The Versions

20/06 2018

dev-master

9999999-dev

Core provides a unified interface for building API Clients

  Sources   Download

MIT

The Requires

 

20/06 2018

1.1

1.1.0.0

Core provides a unified interface for building API Clients

  Sources   Download

MIT

The Requires

 

19/03 2018

1.0

1.0.0.0

Core provides a unified interface for building API Clients

  Sources   Download

MIT

The Requires