Ajeesh
Ajeesh

Reputation: 5860

Where does an API call resides in a repository pattern laravel application?

I am building a web application which has 3 rd party api integrations which include

  1. Payment gateways
  2. Sms vendors
  3. Email providers like mandrill

Now I can have concrete repository classes where functions which talk to my DB resides. As far as I know the repositories are on standard practice used to talk to databases. Now where do I build the logic of calling a 3rd party API resides? Is that what a service provider is meant for? If then can some one show me very basic example of how the whole flow works? For eg sending an sms from a controller by calling the service provider. The question might seems dump but I am not able to get any examples or flow searching it online. There is no real world examples to be seen.

Please give some reference or example if someone has done the same.

TIA!

Upvotes: 4

Views: 2891

Answers (1)

jardis
jardis

Reputation: 687

Repositories are, in the strict sense, for encapsulating methods for advanced access to a set of data.

That being said, there is nothing that says this is the only way to use them. The pattern itself allows for you to group different processes into different places, improving the organization of your code.

At this point one could argue they are no longer repositories, but the most important factor isn't just adhering to design patterns in the strictest of senses. It's using the pattern that suits your applications needs, and sometimes that may also come with distorting the meaning of what that pattern implies.

Not every standard or pattern will perfectly fit into your application, nor should it. You should make changes where needed and break convention when appropriate. This is a matter of judgement. If you think it's simpler to use Repositories as effectively collections of advanced access methods (with application logic in another layer like Services), or collections of application logic. Even both.

Upvotes: 1

Related Questions