Skip to content

Repository files navigation

BaseKit REST API Client

A PHP client for BaseKit's REST API. This client will provide documentation of the services available from the BaseKit API, describing URIs, HTTP methods and input parameters.

Installation

The recommended way of including this package in your project is by using Composer. Add it to the require section of your project's composer.json.

composer require basekit/php-api-client

Usage

useBaseKit\Api\AuthType;
useBaseKit\Api\ClientFactory;
$client = ClientFactory::create(
[
'base_uri' => 'http://api.testing.com',
'username' => 'foo',
'password' => 'bar',
],
AuthType::BASIC, // defaults to basic auth
);
$createSite = $client->getCommand(
'CreateSite',
[
'accountHolderRef' => 123,
'brandRef' => 789,
'domain' => 'test.example.org',
]
);
$client->execute($createSite);

A more detailed example script is available here including account and site creation and populating a site with content using the API.

Testing

Feed an optional handler into the config of clientFactory to control the responses from the http client.

useBaseKit\Api\ClientFactory;
useGuzzleHttp\HandlerStack;
useGuzzleHttp\Handler\MockHandler;
useGuzzleHttp\Psr7\Response;
$client = ClientFactory::create([
'base_uri' => 'https://api.testing.com',
'username' => 'foo',
'password' => 'bar',
'handler' => HandlerStack::create(
newMockHandler([
newResponse(404, [], '"Hello, World! This is a test response."'),
])
) ,
]);
$createSite = $client->getCommand(
'CreateSite',
[
'accountHolderRef' => 123,
'brandRef' => 789,
'domain' => 'test.example.org',
]
);
$client->execute($createSite); // Throws a 404 CommandClientException

License

This software is released under the MIT License.

About

A PHP client for BaseKit's REST API

Resources

Stars

2 stars

Watchers

24 watching

Forks

Releases

Packages

Used by

Contributors

Languages