Client Side API Access Trouble

Here there everyone, I couldn’t find my answers in another thread so I thought I would ask myself.

I am currently in a course learning web development and have been assigned a project to make a basic web app that accesses multiple APIs, solely from the client-side. I want to make an app that checks current top streams on twitch based on a search, but am having trouble accessing the API. Despite having what I believe to be all of the proper headers and parameters (Client-Id, Etc.), I am getting CORS errors. I asked my teacher for help, but he had the same problems and could only get access to the API by using NODE, which I haven’t learned yet and isn’t allowed for this assignment.

Is it possible to access the API from exclusively the client-side, or is this a fruitless endeavor? Any tips or help would be appreciated!

What are the URLs you’re requesting and what headers are you setting? A simple fetch should work in browser.

e.g.

fetch('https://api.twitch.tv/helix/streams', { headers: { authorization: 'Bearer xx' } })
.then(r=>r.json()).then(function (r) {
    console.log(r); // { data: [ ... ], pagination: { ... } }
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.