I'm looking in the Laravel documentation, in several places, but I'm still unsuccessful. I'm looking for somewhere that has a tutorial on how to consume an api with laravel!
I'm looking in the Laravel documentation, in several places, but I'm still unsuccessful. I'm looking for somewhere that has a tutorial on how to consume an api with laravel!
Regardless of what your Framework is, before you consume something you need to understand what an API really is. This will make it easier.
See:
An API is nothing more than a set of public (or not) links that will provide data in a specific format (lately JSON).
Note that, in other words, you need to make your Laravel access links and interpret their return.
So you need ideas to make requests through your system. For this, we have some options:
Pure CURL call with PHP link
Call CURL via Shell_exec (for linux); link
Some package that abstracts the process: link
Regardless of the choice, you will be in any case making a request to another server, in this case providing the API service you need.
In terms of architecture, I believe the ideal for this is you do not use the controller itself, but rather a Services layer for this process.
An example of this are systems that have Free Market integrations, I have an application like this and, in this case, I set up a service that is responsible for all the negotiations that involve the API. This makes the process easier because once done, I no longer need to think about how the API actually works, just use my mounted service that abstracts the process.
Alternative 1:
Alternative 2:
Alternative 3: