The OPTIONS Preflight Request
What you'll learn: How browsers use OPTIONS requests to check permissions before sending certain cross-origin requests.
When you learned about Simple vs Preflight Requests, you discovered that some cross-origin requests need extra permission checks. The OPTIONS preflight request is how browsers perform that safety check before your actual request flies.
How the Preflight Dance Works
Think of it like asking permission before entering someone's home. Before your browser sends that PUT request with custom headers to a different domain, it first sends a quick OPTIONS request asking: "Hey, is this okay?"
The preflight OPTIONS request includes special headers that describe what your real request wants to do:
Access-Control-Request-Method: The HTTP method you plan to use (PUT, DELETE, etc.)Access-Control-Request-Headers: Any custom headers you're planning to sendOrigin: Where the request is coming from
The server responds to this OPTIONS request with its own set of Access-Control-Allow-* headers, essentially saying "Yes, you can do that" or remaining silent (which means "No").
What Happens Next
If the server approves, the browser proceeds with your actual request. If not, the browser blocks your request entirely and throws a CORS error—your JavaScript never even gets to make the real call.
The preflight happens automatically and invisibly. You don't write code to trigger it; the browser handles it based on the request characteristics you already learned about (custom headers, certain methods, content types beyond simple ones).
Key Takeaway: The OPTIONS preflight request is an automatic safety checkpoint where browsers ask cross-origin servers for permission before sending complex requests, ensuring servers can protect themselves from unexpected operations.