What is CORS?

Cross-Origin Resource Sharing (CORS) is an HTTP-header-based mechanism that allows a server to specify which origins (domain, scheme, or port) other than its own are permitted to load resources (responses) in a browser.

A cross-origin HTTP request occurs when a client makes a request to a resource located at a different origin (i.e., a different domain, protocol, or port) than the client's own origin.

Key Points:

Example Scenario:

Enabling CORS in Spring Boot

In a Spring Boot application, CORS can be enabled using the @CrossOrigin annotation at the class or method level in a @RestController. This allows cross-origin HTTP requests from JavaScript clients.

Usage:

@CrossOrigin(origins = "<http://localhost:3000>")
@RestController
public class ProductController {
    // REST API methods
}

Notes: