Send API Key in headers
matiaslopezd opened this issue ยท 6 comments
How I can send the API key in headers with this library?
Also, I believe is too necessary to suggest using the "Authorization" header to maintain safe the API Key, instead of the param in the URL.
Thanks!
The solution to use really depends on your use case. As you said, using a header is a good practice in general. You can find an example of how to use the Authorization header on the next page:
@lpellegr thanks, but I try to do with this library. Now I see that is possible to send options to IpregistryClient
like apiKey
, timeout
, and apiUrl
in the first param.
const {IpregistryClient, DefaultCache, IpregistryRequestHandler} = require('@ipregistry/client');
const options = { apiKey, timeout, apiUrl };
const cache = new DefaultCache(1000, 3600000);
const iDontKnowWhatParamsReceiveThisFunction = IpregistryRequestHandler(??);
const client = new IpregistryClient(options, cache, ???);
There is documentation related to these params? I want to send the API key on headers :)
Thanks!
EDIT: I want to use the cache feature of this library, that's the reason why I don't a simple request with "Authorization" header from my server.
Oops, I read your original message too quickly. Sorry about that.
An option is to pass a custom RequestHandler implementation that overrides the default one. However, that's really not convenient. Furthermore, I agree with you that we could pass the API key as a header by default.
I will make the changes by Friday, release a new version, and let you know.
Thanks @lpellegr! ๐๐๐
@matiaslopezd It was faster than expected. I have published version 3.1.0:
https://www.npmjs.com/package/@ipregistry/client
Please let me know whether it works as desired.
@lpellegr works perfectly! That commit was too fast! Thanks!!!! ๐๐๐