@Rtransat What API are you wrapping? Is there a case for wrapping the API at all (i.e. are you using multiple services to fetch the same type of data)?
Usually, you would create an interface, and then have classes that implement those methods, but themselves wrap a client library.
I realise that’s a bit much to take in. @JeffreyWay did a video not so long ago where he subscribed users to a newsletter, but wrapped the MailChimp API in case you wanted to switch to an alternative service like Campaign Monitor. I can’t for the life of me remember which lesson this was though. That scenario would yield interfaces/classes like this, though:
interface NewsletterService
{
public function subscribe($email);
}
class MailChimp implements NewsletterService
{
public function __construct(MailChimpClient $client)
{
$this->client = $client;
}
public function subscribe($email)
{
$this->client->subscribeUser($email);
}
}
class CampaignMonitor implements NewsletterService
{
public function __construct(CampaignMonitorClient $client)
{
$this->client = $client;
}
public function subscribe($email)
{
$this->client->addUser($email);
}
}
Please note: I made the class names of the MailChimp and Campaign Monitor clients up; I don’t actually know what their class names are off-hand. But if you look at the implementations, you’ll see both my classes implement the NewsletterService interface and thus a subscribe method, but the methods I’d call on the underlying $client class are different.
Hopefully this should point you in the right direction, as you don’t mention what scenario you need to wrap APIs for, so you should be able to take this example and apply it to your scenario.