Full Stack Developer Interview Question

Why does the browser send an OPTIONS request before some of our API calls, and how do you stop it failing?

What the interviewer is probing, how to structure your answer, and a spoken example you can adapt.

Quick answer

That OPTIONS call is the CORS preflight. Browsers send it whenever a cross origin request is not simple, which covers any custom header, a JSON content type, or a method other than GET, HEAD or POST. Your server has to answer that OPTIONS with Access-Control-Allow-Origin, Allow-Methods and Allow-Headers that actually cover the real request, plus Allow-Credentials and a concrete origin if cookies are involved.

Why interviewers ask this

Everyone has been blocked by CORS; far fewer can explain it. The interviewer wants to know whether you understand that CORS is a browser enforced policy protecting the user, not a server side access control, because candidates who miss that tend to suggest disabling it or proxying around it in ways that create real security holes. Naming the simple request rules shows you debugged it properly rather than pasting a wildcard.

How to structure your answer

  • Say what triggers a preflight versus a simple request.
  • List the response headers the server must return.
  • Cover the credentialed case and why wildcards fail there.
  • Clarify that CORS protects the browser user, not your server.

Example answer

Spoken example, first person

The preflight is the browser asking permission before it sends anything with side effects. A plain GET with no custom headers is a simple request and goes straight out, but the moment you add an Authorization header or send application/json, you get the OPTIONS first. When it fails, I check three things in order: does the server answer OPTIONS at all, does Access-Control-Allow-Headers list every header the real request sends, and is the origin echoed exactly including scheme and port. The credentials case catches people out, because if you send cookies you cannot use a wildcard origin; you have to reflect a specific allowed origin and set Access-Control-Allow-Credentials to true. I also set Access-Control-Max-Age so the browser stops preflighting every single call. The thing I make sure a team understands is that none of this protects the API. Anything that is not a browser ignores CORS entirely, so authorization still has to be enforced on the server.

Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.

See how it works

Follow-up questions to expect

  • Why can you not use a wildcard origin with credentials?
  • What does Access-Control-Max-Age actually do?
  • How would you handle a legitimate third party integration calling this API?

Related full stack developer questions

Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.

Predict my questions

Rehearse the hard questions before they are asked

Practise with a live copilot, then walk in ready. A $29 Session Pass gets you through the interview with no subscription and no lock-in.

Get GhostPilot