how to use a response from an api request

i got this response from an api request and i jusr want to find out how i can use use this information? Is it like an array where i can access the elements because that does not seem to be working. Also what is the procedure to use this in html or can i only use javascript to use it? Not sure if what i said makes sense lol
No description
9 Replies
Aoi
Aoi9mo ago
@greenleaf02, this topic is more related to #front-end . Posting there will get you better response
missymae
missymae9mo ago
it's a JSON object. You can read the first section here https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch Here is an example.
async function catConsole() {
await fetch("https://catfact.ninja/fact").then((res) =>
res.json().then((res) => console.log(res.fact))
);
}
async function catConsole() {
await fetch("https://catfact.ninja/fact").then((res) =>
res.json().then((res) => console.log(res.fact))
);
}
MDN Web Docs
Using the Fetch API - Web APIs | MDN
The Fetch API provides a JavaScript interface for accessing and manipulating parts of the protocol, such as requests and responses. It also provides a global fetch() method that provides an easy, logical way to fetch resources asynchronously across the network.
Clever Tagline
Clever Tagline9mo ago
What's the API? That response looks very similar to a weather API that I've used. API integration is more back-end than front-end. Even if the result is meant to be used on the front-end, the question (as I read it) is more about how to access the data at all.
Jochem
Jochem9mo ago
writing the API is backend, consuming the API is frontend it's a valid redirect, and regardless #ui-ux isn't the right place for it
Clever Tagline
Clever Tagline9mo ago
That depends on the context. A good chunk of what I do is write serverless functions to pull database records via API, process the data, then update other database records via further API calls. I'm consuming the API data purely on the back-end.
Jochem
Jochem9mo ago
let me rephrase that in this context then: The OP has a screenshot of a browser console. If it runs in the browser, it's frontend
Clever Tagline
Clever Tagline9mo ago
I apologize if my comments came off as confrontational. Admittedly the vast majority of my work with APIs is in back-end environments, so I suppose I tend to think of them mostly in that context.
greenleaf02
greenleaf02OP9mo ago
its from a site called Open Weather. Is this one you have used?
Clever Tagline
Clever Tagline9mo ago
Yup. In my case, I have an Airtable automation that runs daily and puts the upcoming week's sunrise and sunset data into a table. I then subscribe to a calendar view from that table in Apple Calendar, which gives me a rolling update of sunrise and sunset data wherever I have access to that iCloud calendar subscription.
Want results from more Discord servers?
Add your server