CORS is an HTTP-based mechanism that lets you request data from one URL to a different URL.
Let's talk about it in a bit more detail. π§΅ππ»
CORS stands for Cross-Origin Resource Sharing.
Half of the definition is clear by the abbreviation. CORS allows a server to share resources with browsers having different origins.
Let's try to understand cross-origin requests via an example:
Suppose you're making an HTTP request from "a .com" to "b .com". That's a cross-origin request.
Often, you get an error while you're trying to request from a different URL.
This happens because browsers implement a same-origin policy for security reasons in which clients can make requests to the same origin without any errors.
Fun Fact: π‘
Popular XMLHttpRequest and the Fetch API that we all have been using for a while follow the same-origin policy.
Moving forward ππ»
π How CORS Works
The server adds the `Access-Control-Allow-Origin` header in the response, which must be the same as the `Origin` header of the request. If this is not the case, the browser will prevent the data from being shared with the client.
A few HTTP request methods cause side effects on the server, and these types of request methods must be pre-flighted.
Let's see what exactly Preflighted requests are ππ»
π Preflighted requests
The browser first sends the OPTIONS HTTP request to the server to ensure the actual request is safe to send.
In response, the server sends the `Access-Control-Allow-Methods` header with the allowed HTTP request methods values.
For better understanding, take a look at this infographic ππ»
With that being said, that's pretty much it for this thread.
Give it a retweet if you think this might be helpful for someone. Follow us @Rapid_API for more excellent content. π
β’ β’ β’
Missing some Tweet in this thread? You can try to
force a refresh
Here are Top 5 Image Search and Image Recognition APIs you can use in your next project.
Thread π§΅ππ»
1οΈβ£ Imgur
- Imgur is an online image sharing and image hosting service. Imgurβs API exposes the entire Imgur infrastructure via a standardized programmatic interface.
Let's try to get a quick introduction to the REST API in the following ten tweets.
A Thread π§΅ππ»
Before jumping onto REST
An API is an Application Programming Interface that lets you connect two computers, where one computer or application requests the data from the server.
RESTful APIs are the most famous type of API.
REST APIs are APIs that follow standardized principles, properties, and constraints.
You can access resources in the REST API using HTTP verbs. ππ»