Skip to content
Learn Netverks

Lesson

Step 25/36 69% through track

fetch-http-client

fetch as HTTP client

Last reviewed May 28, 2026 Content v20260528
Track mode
nodejs_server
Means
Node sandbox
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches fetch as HTTP client: the syntax, APIs, and habits you need before advancing in Node.js.

HTTP routing and middleware appear in every Node API interview—know request/response objects and status codes.

You will apply fetch as HTTP client in contexts like: REST APIs, webhooks, and BFF layers behind React or mobile clients.

Run JavaScript on the Node runner when configured—never mix arbitrary shell commands in lessons.

When you can explain the previous lesson's ideas without copying starter code.

Node 18+ includes global fetch for calling external APIs—same API as browsers, returning Promises and Response objects.

GET and POST

const res = await fetch('https://api.example.com/users');
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const users = await res.json();

await fetch('https://api.example.com/users', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ name: 'Ada' }),
});

Error handling

fetch only rejects on network failure—404 still resolves. Always check res.ok or status codes.

Playground note

External network may be restricted in sandbox—this lesson demonstrates patterns; run against real APIs locally.

Important interview questions and answers

  1. Q: fetch vs axios?
    A: fetch is built-in; axios adds interceptors, timeouts, and automatic JSON in many setups—both valid.
  2. Q: Abort fetch?
    A: AbortController with signal—cancel on timeout or user navigation.

Self-check

  1. Does fetch throw on 404?
  2. How do you send JSON in POST body?

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • fetch vs axios pick?
  • Timeout handling?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump