Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

imajkumar's avatar

How to Use external API in laravel

I have a external API . how to use in laravel with ajax based request. any one suggest me .. how to use Thanks

0 likes
5 replies
imajkumar's avatar

@SCHEMEZA - I am using RESTAPI ..with the help of token all request is granted . so how to manage token to save not in session or local storage

scheMeZa's avatar

@IMAJKUMAR - I assume that your application is built on interacting with this API?

In such circumstances, I like to use/create a config file for the purpose of storing configurations related to the API:

<?php
return [
    'api-token' => env('API_TOKEN', '')
];

Then you can add your API's token to your .env file, and a stub for API_TOKEN in your .env.example.

When making API calls, you can then easily use the config helper method:

public function getApiToken() {
    return config('<config_file_name>.api-token');
}

Please or to participate in this conversation.