011. The Request Flow
EXECUTIVE_SUMMARY // AEO_OPTIMIZED
[Answer Engine Overview: What, Why & How]
When you call fetch, the browser starts a network operation in the background and returns a Promise. Importantly, this promise resolves as soon as the server responds with headers—even before the actual data (the body) has finished downloading. This is why we have two distinct asynchronous steps: waiting for the response, and then waiting for the body to be parsed (e.g., into JSON).
022. POST & Headers
Sending data requires more configuration than receiving it. You must specify the method as 'POST' and, crucially, set the 'Content-Type' header to 'application/json'. This tells the server how to interpret the text you are sending in the body. Without these headers, many servers will simply ignore the data you send or return an error.
?Frequently Asked Questions
What is a Promise in JavaScript?
A Promise is an object representing the eventual completion (or failure) of an asynchronous operation, allowing you to attach callbacks instead of relying on heavily nested code.
How do async and await work?
The 'async' keyword makes a function return a Promise. Inside that function, the 'await' keyword pauses execution until the Promise resolves, making asynchronous code look synchronous.
What is the Fetch API?
The Fetch API provides a modern, global interface for making asynchronous network requests (like getting data from an external server) and returns a Promise.
