#Adding header in json api

21 messages · Page 1 of 1 (latest)

heady fiber
#

Wdym by “putting header in getStaticProps”?

ionic cloud
#

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

heady fiber
#

What is that API key in the header for?

ionic cloud
#

for configuration

heady fiber
#

As in browser js will take that api key and use it?

#

Then just pass that api key in one of the props

ionic cloud
heady fiber
ionic cloud
#

yeah

#

okay

heady fiber
#

Then you can use axios if you like, or if you use fetch,

fetch(“…”, { headers: { your headers here } })

ionic cloud
#

can't we do it with async ?

#

like

heady fiber
#

Yes we can?

ionic cloud
#
  const res = await fetch("https://...com", {header: {headers}})
  const data = await res.json
}```
#

like this ?

heady fiber
#

then

export default function Page({ data }) {
  return <div>{data.name}</div>;
}

for example