Glossary

Preflight request explained.

A preflight request is the automatic OPTIONS call a browser makes before certain cross-origin requests, asking the server whether the real request, with its method and headers, is allowed.

Definition

How a preflight request works

Browsers enforce CORS to stop one site from quietly making sensitive requests to another on a visitor's behalf. For requests that could have side effects, the browser doesn't send the real request straight away. It first sends a small OPTIONS request to the same URL, carrying two headers: Access-Control-Request-Method names the method the real request will use, and Access-Control-Request-Headers lists any custom headers it will send. The server answers with its own Access-Control-Allow headers describing what it permits.

If the real request fits inside that permission, the browser proceeds and sends it; if not, the browser blocks it and your fetch fails before the real call ever leaves. This check happens once and can be cached for a window the server sets.

Not every request triggers it: a simple request (a plain GET, or a POST with a form-style content type and no custom headers) skips the preflight, which is exactly why a normal HTML form POST to a form backend goes straight through. Add a custom header or a JSON content type to that same submission from JavaScript and the browser will preflight first, so FormWire's endpoint answers OPTIONS with the right allow headers.

Related questions

Want to see it working?

Read the docs
Ready in a minute

Post to an endpoint that answers correctly.

Free tier forever. No credit card required.