Building SDKs
Saloon SDK Template
Getting Started
Example SDK Connector
<?php
namespace Sammyjo20\TMDB;
use Sammyjo20\Saloon\Http\SaloonConnector;
use Sammyjo20\TMDB\Responses\TMDBResponse;
use Sammyjo20\Saloon\Traits\Plugins\AcceptsJson;
class TMDB extends SaloonConnector
{
use AcceptsJson;
protected string $apiBaseUrl = 'https://api.themoviedb.org/3';
protected array $requests = [];
// Define the base URL.
public function defineBaseUrl(): string
{
return $this->apiBaseUrl;
}
// Constructor requires the token.
// Also allow to overwrite the API base URL for local servers.
public function __construct(string $token, string $baseUrl = null)
{
$this->withTokenAuth($token);
if (isset($baseUrl)) {
$this->apiBaseUrl = $baseUrl;
}
}
// Headers that will be used on all requests
public function defaultHeaders(): array
{
return [
'Content-Type' => 'application/json',
];
}
// Default Guzzle Config Options
public function defaultConfig(): array
{
return [
'timeout' => 30,
];
}
}Using the SDK connector
Recommended Method: Using Requests Directly
1. Make a Saloon Request
2. Call your request
Method Two: Create Request Collections
Example
Individual Requests
Customising the request methods
Request Collections
IDE Auto-Completion
Custom Responses
Last updated