API / APIGEE Gateway Interview Questions
How does Apigee handle CORS (Cross-Origin Resource Sharing)?
CORS must be handled by Apigee when web browser clients make API calls cross-origin. Apigee deals with two types of CORS requests: simple requests (handled in the response flow) and preflight OPTIONS requests (which must be responded to immediately, before reaching the backend).
<!-- Step 1: Handle preflight OPTIONS requests These must return 200 immediately without hitting the backend --> <Flow name="OptionsPreFlight"> <Condition>request.verb == "OPTIONS"</Condition> <Request> <Step><Name>AM.AddCorsHeaders</Name></Step> <Step><Name>AM.ReturnOptions</Name></Step> <!-- returns 200, no backend call --> </Request> </Flow> <!-- Step 2: Add CORS headers to all responses --> <PostFlow name="PostFlow"> <Response> <Step><Name>AM.AddCorsHeaders</Name></Step> </Response> </PostFlow> <!-- CORS headers AssignMessage policy --> <AssignMessage name="AM.AddCorsHeaders"> <AssignTo createNew="false" type="response"/> <Set> <Headers> <Header name="Access-Control-Allow-Origin">*</Header> <!-- Or restrict to specific origins: <Header name="Access-Control-Allow-Origin"> {request.header.origin} </Header> --> <Header name="Access-Control-Allow-Methods">GET, POST, PUT, DELETE, OPTIONS</Header> <Header name="Access-Control-Allow-Headers">Content-Type, Authorization, x-api-key</Header> <Header name="Access-Control-Max-Age">3600</Header> </Headers> </Set> </AssignMessage> <!-- Return 200 for OPTIONS without calling backend --> <AssignMessage name="AM.ReturnOptions"> <AssignTo createNew="true" type="response"/> <Set><StatusCode>200</StatusCode></Set> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> </AssignMessage>
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
