Summer sale! Save 50% on access to our entire library of courses.Join here →
Laravel

Best way to consume external api

I'm building a web app around a external api. What is the best way to organize the logic? Is ok to do something like this:


class TestService {

   public function getItemById($id) {

  }

   public function getAll() {

  }

}

and call these functions inside the controller

lucas27742
lucas27742
1
2
191
alex
alex
Moderator

You might want to take a look at Saloon.

It allows you to create SDK like integrations with any API and provides the ability to create a wrapper pretty much like what you're doing manually here.

At first, it might seem a little overwhelming (depending on how complex you need the functionality to be), but reading through the docs should make it click.

Haz
Haz
Moderator

@lucas27742

If you are a visual learner, you may find the following video useful.

https://www.youtube.com/watch?v=r3AU6uYQGt4