Where to put API key I am working on a project with some content from another site using API.
I got the URL and API key and did not get where to put the API key in the controller.
function index()
{
$collection = Http::get("https://apiwesiteaddress...../stats");
return view('stats', ['collection'=>$collection]);
}
Do you mean "Where do I store it safely"? Or "Where to I put it in Http::get" ?
@Sinnbeck I am just started learning it. So I want to know where to put it in Http::get and also the safe place to store it.
First, tell me where to put the API key in Http::get, and then please tell me how to store it safely.
@webfuelcode
Ok. Safely storing it first
add this to your env
SOMESITE_API="myapikey"
and in a config file (you could create a new one, or use one of the existing), add this
'somesite_api_key' = env('SOMESITE_API'),
and use in code
$key = config('nameofconfigfile.somesite_api_key');
Now for the "how to". That depends on the API docs. Can you provide them?
@webfuelcode Check the docs and see that it uses a header
$response = Http::withHeaders([
'X-Access-Token' => $key
])->get(...)
Please sign in or create an account to participate in this conversation.