Shalker21's avatar

3rd party api implementation

Hay,

I have some questions about api consuming. What are the best way to use 3rd party apis? Using resources or services?

let's say we have ecommerce shop and we need to connect to ERP system. We can create base class with all ERP provided data, and in there we connect via guzzle? Then extends that class into children classes?

0 likes
3 replies
Snapey's avatar

If this is likely to be the only ERP it needs to connect to, I would create a single Service class with functions for all the required API methods

Not sure I would go to the bother of extending it with child classes

Probably use the Http client rather than guzzle directly - depends what Laravel version you are on.

1 like
Shalker21's avatar

@Snapey A ok, I get a point on that. And lets say we have multiple shipping gateways, we will create base service container and extend it to child service containers for specific shipping gateway, right? What about API resources? Or what about repository pattern?

Snapey's avatar

@Shalker21 Yes, correct for shipping gateways

In my experience very few projects use repository pattern because you just end up duplicating most of what is in Eloquent models.

Please or to participate in this conversation.