Search code examples
restcorshttprequest

Difference between CORS and HTTP requests to a third party API


Are GET requests considered CORS since the request is obtaining resources from another domain?

I get from Wikipedia that CORS is:

"a mechanism that allows restricted resources (e.g. fonts) on a web page to be requested from another domain outside the domain from which the resource originated."

However given this example:

$.ajax({
    type: "GET",
    url: "https://api.twitch.tv/kraken/base",
    success: function(data){
      //do stuff
    }
});

If www.mywebsite.com (a domain) made the above GET request to Twitch (a domain outside the domain) does this count as CORS?


Solution

  • A HTTP request is a HTTP request.

    Normally when you're on one domain, you are restricted to do stuff on another domain. This is called the browser sandbox.

    CORS is a way for third party domains (twitch in your case) to grant you access after all.

    In the particular example you state, twitch will indeed need to set the appropriate CORS headers to give you access. If twitch doesn't do this, you will not be able to read data.

    Note that your code sample is horribly broken.