ApiConnector Module
Purpose
Provide a standard approach of connecting to third party API services.
Usage
- Create a new connector class that extends the
BaseApiConnectorclass that will be used to make API calls through your API client of choice (either Saloon, Guzzle or third party SDK.) - In the same connector, implement the
ApiConnectorinterface. - Configure your connect in
YourModule/Config/district_api_connectors.phpfile.
'[apiName]' => [
'connector' => YourConnector::class, // Extends BaseApiConnector.
/*
|--------------------------------------------------------------------------
| Config used by Api client to populate default settings.
|--------------------------------------------------------------------------
*/
BaseApiConnector::CONNECTOR_SETTINGS_KEY => [
'someHost' => env('SOME_HOST'),
'someUser' => env('SOME_USER'),
'secretToken' => env('SECRET_TOKEN'),
],
],
- Optional - recommended - create a new service class (e.g
ApiNameService) that will be used to call your connector to wrap common API calls. e.g
$optionalCustomSettings = [
BaseApiConnector::CONNECTOR_SETTINGS_KEY => [
'someHost' => 'http://somehost.com',
'secretToken' => 'abc123'
]
];
$jiraService = JiraService::new($optionalCustomSettings);
$issue = $jiraService->getIssue($issueKey);
/**
* Get a specific Jira issue.
*/
public function getIssue($issueKey): Issue
{
return $this->getJiraConnector()->getIssueService()->get($issueKey);
}