Bhoami Khona
Bhoami Khona

Reputation: 87

Access JSON Data using URL, Header Prefix, and Access Key

I have been given URL and Authorization e.g.

URL: “https://xxxx.com/_xxx/xxx/_all” Authorization: “Header xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”

How can I use GET API to get the Response JSON using Javascript and React.js.

Upvotes: -1

Views: 103

Answers (1)

Try this code:

fetch("https://xxxx.com/_xxx/xxx/_all", {
   method: "GET",
   headers: {
   Authorization: "Header xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
 },
 })
 .then((response) => response.json())
 .then((data) => console.log(data))
 .catch((error) => console.error(error));

Or you can use axios:

import axios from "axios";

axios
.get("https://xxxx.com/_xxx/xxx/_all", {
headers: {
  Authorization: "Header xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
 }
})
.then((response) => console.log(response.data))
.catch((error) => console.error(error));

Upvotes: 2

Related Questions