How to call Laravel internal API ?

Tilak poudel
2 min readNov 9, 2020
laravel 8 REST API

Today I am sharing my experience how i spend a day for consuming an internal API within the same laravel application and ended up with this post ….

Are you ready to get your query solved ?? Lets get started …… :)

Query: How can we make a internal API call within the same laravel Api application from the Controller ?

Answer: Ok lets go through the post to get answered .

Note :: We can use http-clients called Guzzle HTTP client for making an external api call in laravel app or we can go with axios (https://github.com/axios/axios).

See more about laravel http request at :

https://laravel.com/docs/8.x/http-client

(https://github.com/axios/axios).

If you have an API, which you also use on your site..then you might want to get the data from the API by making an internal request.

Don’t forget to include it before making the request.

use Illuminate\Support\Facades\Route;

In this way you can make an internal api call in laravel app .

WAIT WAIT its not over !!!!!!!!!(https://github.com/axios/axios).

What if you have to pass some data in the header(like authorization token) with the call ???

Then you can include the headers as :

OK By now you might have got your data returned by api ..

Bonus Section

You can get your data as defined in your response sent by the api call ….

In my case i got my data and passed to the view as below :

So the final code looks as:

Thank You…

If You found the content useful . DON’T forget to give a applause and let me know if your problem is solved in comment section :)

See You soon in the next post …. SO keep Following …. :)

Happy Coding …. :)

--

--