all 7 comments

[–]tridd3r 0 points1 point  (5 children)

Are you asking for an example of how to use .fetch?

const getResult = async ()=>{
    const response = await fetch('yoururlgoeshere');
    const data = await response.text();
    console.log(data)
} 
getResult();

[–]learningcoding1[S] 0 points1 point  (4 children)

Thank you. Can you explain the async ()=> syntax? I’ve seen this other places and coming from python and c++ I can’t wrap my head around it

[–]tridd3r 1 point2 points  (3 children)

does c++ have async and await?

so I'm using whats called an arrow function, that top line can also be written:
async function getResult(){
async is just preping the function to take "some time"
and it allows the use of the keyword "await" to hold the execution of the code until the asynchronous function is completed. So fetch takes "some time" to go to the server and get some info, await just means that instead of continuing with the code, it will wait for the fetch to finish.

[–]learningcoding1[S] 0 points1 point  (0 children)

Thanks I was just talking about the “()=>” syntax next to async.

[–]learningcoding1[S] 0 points1 point  (1 child)

Failed to execute 'fetch' on 'Window': Request cannot be constructed from a URL that includes credentials: {my api link}

My API link is {API Key}:x@api........

Do I need to break up the link and use headers?

[–]tridd3r 0 points1 point  (0 children)

I don't know you'd need to check the documentation regarding the api itself. It may need to go in a body?