Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Djomobil's avatar

The best way for my problem (One class using multi external api service)

Hello,

I search the best way, to implement all external services.

Example :

I would like to create a method to get price by all registrar api (InternetBS, NameBright, cloudflare, GoDaddy, etc..)

i imagine something like this :

//Get Information about domain :

$domain = $request->input('domain');
$registrarService->getInfo($domain);

//Register a domain :

$registrarSelected = $request->input('registrar');
$registrar = new $registrarSelected();
$registrar->register($domain);


and the method returning :

Registrar 1 : All informations from api Registrar 2 : All informations from api (etc...)

but my problem is how to :

What the best : controller / Interface / Trait / Service ?

how call all api with specific crendential (env variable ? like INTERNETBS_TOKEN=****** , .... )

What the best way? Thank lot

0 likes
2 replies
bugsysha's avatar

From controller call your service which will orchestrate everything required to fulfill this task. Credentials go into .env file.

drewdan's avatar

Maybe use a service provider to create instances of the class which interacts with the relevant credentials, so when you resolve the class out of the container, they already have the correct credentials and you can just call methods on them?

Please or to participate in this conversation.