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

salahy's avatar

Best Design Pattern for consuming multiple API's

Hi, I doing a project where I need to call different api's but all serve the same thing. but I can't figure out what is the best practice to do it

what I have basically is API's for pharmacies all of them serve 3 things

  1. get stock for medicine
  2. order certain medicine
  3. list all available medicines

you should know, some of them is XML some is SOAP and others JSON, each of them different structure .. etc

but all of them I need to retain unified api structure for the 3 methods.

I was trying to use repository pattern but still not sure

any tips could be helpful Thanks

0 likes
5 replies
salahy's avatar

Hello Punksoild, I checked the answer, its very similar to what I have in mid, is to use repository pattern, but is this scalable, imagine having 200 API's ?

Punksolid's avatar

Yes @salahy, its very scalable. You could do an interface very well defined to use it for all 200 classes. And when you start seeing similar processes through lets say 10 different Pharmacies APIs, you could add a trait or a parent class to do that part of the process.

In some way you cant dismiss the decode/mapping part for each api response.

You don't need to do any of the 200 classes to have it working, you will just have to add each one after you finish it, so it will not interfere with the already done classes.

nbj's avatar

@salahy Why not simply create classes with specific implementations for each API, and make sure they adhere to the same contract (interface/abstract class)? and then simply inject APIs as dependencies where needed? At least that is how I would go about it :)

Please or to participate in this conversation.