Course:Internet & Tools/
Lesson

ChatGPT wrote a beautiful fetch call. The code looks correct, proper URL, proper headers, proper JSONWhat is json?A text format for exchanging data between systems. It uses key-value pairs and arrays, and every programming language can read and write it. body. But the component shows "Loading..." forever, or the data comes back empty, or you get a cryptic error. The code is not the problem; the HTTPWhat is http?The protocol browsers and servers use to exchange web pages, API data, and other resources, defining how requests and responses are formatted. request is. And the only way to see what actually happened over the wire is the Network panel.

Every APIWhat is api?A set of rules that lets one program talk to another, usually over the internet, by sending requests and getting responses. interaction AI generates is a black box until you open the Network panel and see what the browser actually sent and what the server actually returned.

Reading the request list

Every row in the Network panel represents one HTTPWhat is http?The protocol browsers and servers use to exchange web pages, API data, and other resources, defining how requests and responses are formatted. request. The columns give you an immediate overview:

ColumnWhat it showsWhat to check for AI code
NameEndpoint pathDid AI use the right URL?
StatusHTTP status codeIs it 200 or an error code?
TypeResource type (fetch, xhr, script)Filter to Fetch/XHR for API calls
InitiatorWhat triggered the requestWhich file and line made this call?
SizeBytes transferredIs the response empty (0 B)?
TimeTotal request durationIs the server responding at all?
WaterfallVisual timeline of the requestWhere is the time being spent?

Click "Fetch/XHR" in the filter bar to show only APIWhat is api?A set of rules that lets one program talk to another, usually over the internet, by sending requests and getting responses. calls. This immediately hides all static assets (images, stylesheets, scripts) and lets you focus on the requests AI generated.

02

HTTPWhat is http?The protocol browsers and servers use to exchange web pages, API data, and other resources, defining how requests and responses are formatted. status codes, what they mean for your AI code

When an AI-generated fetch call fails, the status codeWhat is status code?A three-digit number in an HTTP response that tells the client what happened: 200 means success, 404 means not found, 500 means the server broke. tells you exactly what went wrong.

StatusMeaningCommon AI mistake
200SuccessNo problem, check the response body shape
201CreatedPOST worked, but AI might not handle this differently from 200
400Bad RequestAI sent malformed JSON or missing required fields
401UnauthorizedAI forgot to include the auth token or session cookie
403ForbiddenAuth token is present but lacks permission, wrong scope or role
404Not FoundAI used the wrong endpoint URL or wrong HTTP method
422UnprocessableRequest shape is wrong, field names or types don't match API spec
429Too Many RequestsAI code is calling the API in a tight loop without throttling
500Server ErrorNot your fault, but AI might be sending data that crashes the server
// Copilot generated this - but it returns 401
const response = await fetch('/api/users', {
  method: 'GET',
  headers: {
    'Content-Type': 'application/json'
    // BUG: Copilot forgot the Authorization header!
  }
});
A 304 Not Modified response means the browser already has a cached copy. This is normal and efficient, not an error. If you are debugging and want to force a fresh response, check "Disable cache" in the Network panel toolbar.
03

Inspecting a request in detail

Click any request to open a detail pane with several tabs:

Headers tab

Shows the request method, URL, status codeWhat is status code?A three-digit number in an HTTP response that tells the client what happened: 200 means success, 404 means not found, 500 means the server broke., and all headers. This is where you check for:

  • Missing Authorization header (most common AI mistake)
  • Wrong Content-Type (AI sends text/plain instead of application/json)
  • CORSWhat is cors?Cross-Origin Resource Sharing - a browser security rule that blocks web pages from making requests to a different domain unless that domain explicitly allows it. errors (missing Access-Control-Allow-Origin in response headers)
Request Headers (what your browser sent):
  Authorization: Bearer eyJhbG...   ← Is this present? Is the token valid?
  Content-Type: application/json    ← Is this correct for the API?

Response Headers (what the server returned):
  Access-Control-Allow-Origin: *    ← Is CORS configured?
  Set-Cookie: session=abc123        ← Is the session being set?

PayloadWhat is payload?The data sent in the body of an HTTP request, such as the JSON object you include when creating a resource through a POST request. tab

Shows the body of the request, the JSONWhat is json?A text format for exchanging data between systems. It uses key-value pairs and arrays, and every programming language can read and write it. you sent in a POST or PUT. If the APIWhat is api?A set of rules that lets one program talk to another, usually over the internet, by sending requests and getting responses. is rejecting your request, compare what you sent against what the API expects.

// ChatGPT generated this POST body
// But the API expects "email", not "mail"
{
  "name": "Alice",
  "mail": "alice@example.com"  // Wrong field name!
}

Preview and Response tabs

Preview shows the response body formatted and syntax-highlighted. Response shows the raw text. If the server returned an error message, it is here, often with specific details about what was wrong.

Timing tab

Breaks down where the time was spent:

PhaseWhat it meansIf it's slow...
QueueingWaiting for a free connectionToo many parallel requests
DNS LookupResolving hostname to IPFirst request to a new domain
Initial connectionTCP handshakeNormal for first request
SSLTLS negotiationNormal for HTTPS, ~50-100ms
Waiting (TTFB)Server processing timeBackend is slow, not a frontend issue
Content downloadReceiving the response bodyResponse is too large, paginate
If TTFB is consistently over 500ms, the bottleneck is server-side. AI-generated code cannot fix a slow backend. But AI does frequently generate requests that fetch far more data than needed, check if the request includes pagination parameters.
04

Debugging CORSWhat is cors?Cross-Origin Resource Sharing - a browser security rule that blocks web pages from making requests to a different domain unless that domain explicitly allows it. errors

CORS errors are one of the most common problems with AI-generated fetch calls. The browser blocks the request, the Console shows a red error, and the Network panel shows the request as failed.

Access to fetch at 'https://api.example.com/users' from origin
'http://localhost:3000' has been blocked by CORS policy:
No 'Access-Control-Allow-Origin' header is present.

In the Network panel, look for a preflight OPTIONS request that appears before your actual request. If the OPTIONS request fails or is missing the right headers, the real request never fires.

// Claude generated this fetch - but it triggers CORS
// because it added a custom header
const response = await fetch('https://api.example.com/users', {
  headers: {
    'X-Custom-Header': 'value'  // This triggers a CORS preflight
  }
});
// Fix: remove custom headers, or configure CORS on the server
05

Copying and replaying requests

Right-clicking any request gives you options for extracting and replaying it:

# "Copy as cURL" gives you something like:
curl 'https://api.example.com/users' \
  -H 'Authorization: Bearer eyJ...' \
  -H 'Content-Type: application/json' \
  --data '{"page":1,"limit":20}'

Paste that directly into your terminalWhat is terminal?A text-based interface where you type commands to interact with your computer. Also called the command line or shell. to replay the request with all original headers and cookies. This removes the browser as a variable and lets you test the APIWhat is api?A set of rules that lets one program talk to another, usually over the internet, by sending requests and getting responses. independently.

"Copy as fetch" gives you the same request formatted as JavaScript you can paste into the Console and run directly, useful for testing modifications to the request.

06

Quick reference

TaskWhere to lookWhat to check
API call not workingNetwork → Fetch/XHR filterStatus code, request URL
Auth failingHeaders tab → Request HeadersIs Authorization header present?
Wrong data returnedPreview/Response tabDoes the shape match what AI expects?
Request body wrongPayload tabDo field names match the API spec?
Slow responseTiming tabIs TTFB high (server) or download slow (payload size)?
CORS errorConsole + NetworkLook for failed OPTIONS preflight request
Reproduce outside browserRight-click → Copy as cURLTest in terminal without browser