#Adding header in json api
21 messages · Page 1 of 1 (latest)
actually I'm trying to pull data from a game database api
but the thing is it contains a API key they sayin to include in header
I'm confused with the official docs
What is that API key in the header for?
for configuration
As in browser js will take that api key and use it?
Then just pass that api key in one of the props
Actually I'm very new to Next js so Idk much abt it so can u just show an example ?
Ah in this case ignore what i said. They meant adding the header to the fetch request
Then you can use axios if you like, or if you use fetch,
fetch(“…”, { headers: { your headers here } })
Yes we can?
const res = await fetch("https://...com", {header: {headers}})
const data = await res.json
}```
like this ?
export async function getStaticProps() {
const res = await fetch("https://...com", {header: ...})
const data = await res.json();
return { props: { data } }
}
then
export default function Page({ data }) {
return <div>{data.name}</div>;
}
for example