HACKER Q&A
📣 alegeaa

How do you add headers in href of an a tag/link?


Hello hackers,

I am stuck on this and I have tried all possible channels available to me. I thought maybe I can find some help here.

So, there is an API endpoint requires a token (API key). However, the full link of the API is meant to be added in the third party app and be opened in the client`s browser while also passing the header information.

For example, the API link is x.com/do_this

the client (of the API) adds the link in their application. When the client`s user clicks the link, it should open x.com/do_this but the client`s API key is needed to show some information when that link is opened.

How do I go about this? I dont mind using AJAX, JS, or any other tech out there that can provide this solution.

Thanks


  👤 quickthrower2 Accepted Answer ✓
That is not directly possible from a link. You will need to use XHR or fetch to make the call to the api. Then use the result to update the page.

This assumes the api responds to the cross-origin request and allows the request (if not you are kind of stuck).

https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequ...

https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API