I have a cURL example of an request to a rest API, but I can't seem to replicate it correctly in JavaScript with fetch. Would any of you please help me out? here is the cURL example:
curl https://api.sparebank1.no/open/personal/banking/accounts/all --header "Authorization:Bearer 9VKwFeoS8QfeQEeFxD5MiOf6YlFQR0nOpLF1ZUrHRrWqp3rY7G13hy"
Thx
Here it is:
fetch('https://api.sparebank1.no/open/personal/banking/accounts/all', {
headers: {
Authorization: 'Bearer 9VKwFeoS8QfeQEeFxD5MiOf6YlFQR0nOpLF1ZUrHRrWqp3rY7G13hy'
}
});
The fetch function takes a first parameter, the URL. The second parameter is an object containing keys that describe your request, such as method or headers.
In our case, it's specifying a headers object. This contains key-value pairs of named headers and their corresponding values.
I recommend viewing MDN (if you haven't), it's a useful resource.