liveBook · Manning

Preflight request

As explained in Build Financial Software with Generative AI (From Scratch)

A preflight request is a browser-generated cross-origin HTTP request that asks whether a subsequent request is permitted before sending it.

A preflight request is a browser-generated cross-origin HTTP request that checks whether a later request is permitted before sending it. It appears when a web page calls an API from a different origin, making CORS configuration part of the developer workflow. section 3.4

Handle preflight behavior by configuring the API deliberately:

  • Allow only expected origins, such as a local dashboard address, instead of using the wildcard origin by default. section 3.4 section 7.5.1
  • Limit permitted methods to those the application uses, such as GET and POST; OPTIONS may be required by some frameworks or versions. section 3.4 section 7.5.1
  • Declare allowed headers and decide whether credentials are permitted for authenticated, cookie-based, or stateful requests. section 3.4

Diagnosing a blocked dashboard request

A page served from http://localhost:3000 requests http://localhost:8000/health/status and receives a CORS error because the API response lacks Access-Control-Allow-Origin. Adding FastAPI's CORSMiddleware with the dashboard origin and GET permission supplies the required policy configuration. section 3.4

How Build Financial Software with Generative AI (From Scratch) covers it

How deep it goes
Explains the browser check and required response policy, then stops short of detailing the HTTP exchange itself.
Examples
Uses localhost dashboard-to-API calls, a missing Access-Control-Allow-Origin error, and FastAPI CORSMiddleware configuration.
What it assumes
Assumes basic browser-to-API requests and introduces CORS, origins, preflight checks, and response policy settings.
What you can do after
Configure FastAPI CORSMiddleware with explicit origins, methods, headers, and credential behavior to resolve cross-origin API access.
How it connects
Connects CORS with cross-origin requests, HTTP methods, HTTP headers, credentials, browser security, and least privilege.

Also explained in

Compare how 3 books explain preflight request →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Financial Software with Generative AI (From Scratch). The section links point to the parts of the book it draws on.