JavaScript required
We’re sorry, but Coda doesn’t work properly without JavaScript enabled.
Skip to content
Gallery
Handbook Backend
Huvudmoment
API-gränssnitt
Protokoll
Säkerhet
Databaskoppling
Fullstack
Agilt Arbetssätt
(Extra)
More
Share
Explore
Javascript
Fetch med Bearer
För att använda ditt bearer token i en Javascript-fetch, ange din header med “bearer” och placera in ditt token därefter:
fetch
(
'https://mitt-api.se/min-endpoint'
,
{
headers
:
{
'Authorization':
`Bearer ${
token
}`
}
}).
then
(
function
(
response
)
{
if
(
response
.
ok
)
{
return
response
.
json
();
}
throw
response
;
}).
then
(
function
(
data
)
{
console
.
log
(
data
);
}).
catch
(
function
(
error
)
{
console
.
warn
(
error
);
});
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
Ctrl
P
) instead.