liveBook · Manning

Fetch API

As explained in JavaScript in Depth

A web-standard JavaScript API for making asynchronous network requests that returns promises for HTTP responses.

Fetch API makes asynchronous HTTP requests and returns promises for Response objects. Each response body is a Web ReadableStream, including in Node.js. section 10.4.2

The surprising boundary appears when one application mixes fetch() with native Node.js HTTP APIs: equivalent HTTP operations expose different stream types. section 10.4.2

Choose the pipeline according to the surrounding stream model:

  • Convert a fetch body with Readable.fromWeb() before sending it through Node.js transforms or stream.pipeline(). section 10.4.2
  • Stay in Web Streams and use pipeThrough() when the rest of the pipeline already follows the platform model. section 10.4.2
  • Account for adaptation costs because conversion performance depends on the pipeline surrounding the response body. section 10.4.2

How JavaScript in Depth covers it

How deep it goes
Contrasts browser, Node.js, and platform stream behavior, but stops short of detailing fetch request options.
Examples
Uses browser fetch(), Node.js fetch(), http.createServer(), Node.js transforms, and stream.pipeline() as boundary cases.
What it assumes
Assumes familiarity with HTTP responses and stream pipelines while exposing the distinction between Web and Node.js streams.
What you can do after
Operate fetch responses by selecting Web Stream composition or explicit Node.js adaptation.
How it connects
Connects HTTP responses with Web Streams, Node.js streams, stream.pipeline(), Readable.fromWeb(), and pipeThrough().

Also explained in

Compare how 2 books explain Fetch API →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of JavaScript in Depth. The section links point to the parts of the book it draws on.