I'm a total newb when it comes to javascript and json. As it will soon show. I had some experience with javascript back 12 or so years ago. But it was minimal. So, go easy on me.
It's difficult to explain exactly what the issue is that I am having. So, I'll make an example here. I have an API url that I need to get another API URL from and then use that json file to create my html page. I can fetch the first json file just fine at, lets say, http://www.thiscarsite.com/API/thecars
And it's set up similar to the following example.
{ "manufacturer": "Cheverolet","model": "Camaro","year": "1990","styles": {"top": "convertible","engine"; "v8","address": "http://www.somesite.com/api/90ChevCamConvV8" }}
As I said, I can get the first json information just fine with fetch/await. Or something as simple as this.
const startUrl = 'http://www.thiscarsite.com/API/thecars';fetch(startUrl) .then(response => { return response.json(); console.log(data); }) .catch(error => { console.error(error); });
I have seen examples where one gets the URL by const newURL = data.styles.address;
But how do I go about getting the address from the example above AND requesting the 2nd json file? I failed to mention that the URL in the first json file can change 3 or 4 times per week. Thus, the need to get it from the first one every time I need to access it.
I know this information is probably easy to find. I'm just not smart enough on the subject to be able to use the proper search terms.
I appreciate anyone taking the time to point me in the right direction.
WHAT I TRIED, With No luck
Tried something like this, my edits to insert the 2nd URL resulted in a failure
fetch('https://example.com/endpoint1') .then(response => { return response.json(); }) .then(data1 => { return fetch(`https://example.com/endpoint2?data=${data1}`); }) .then(response => { return response.json(); }) .then(data2 => { console.log(data2); }) .catch(error => { console.error(error); });
Also, tried using 2 async functions but kept getting errors like "response already called" (or something to the effect)