node-fetch v2.0.0 Release Notes
-
🚀 This is a major release. Check our upgrade guide for an overview on some key differences between v1 and v2.
General changes
- 👍 Major: Node.js 0.10.x and 0.12.x support is dropped
- 👍 Major:
require('node-fetch/lib/response')
etc. is now unsupported; userequire('node-fetch').Response
or ES6 module imports - ✨ Enhance: start testing on Node.js v4.x, v6.x, v8.x LTS, as well as v9.x stable
- ✨ Enhance: use Rollup to produce a distributed bundle (less memory overhead and faster startup)
- ✨ Enhance: make
Object.prototype.toString()
on Headers, Requests, and Responses return correct class strings - Other: rewrite in ES2015 using Babel
- Other: use Codecov for code coverage tracking
- ⚡️ Other: update package.json script for npm 5
- Other:
encoding
module is now optional (alpha.7) - 📦 Other: expose browser.js through package.json, avoid bundling mishaps (alpha.9)
- 0️⃣ Other: allow TypeScript to
import
node-fetch by exposing default (alpha.9)
HTTP requests
- Major: overwrite user's
Content-Length
if we can be sure our information is correct (per spec) - 🛠 Fix: errors in a response are caught before the body is accessed
- 🛠 Fix: support WHATWG URL objects, created by
whatwg-url
package orrequire('url').URL
in Node.js 7+
Response and Request classes
- Major:
response.text()
no longer attempts to detect encoding, instead always opting for UTF-8 (per spec); useresponse.textConverted()
for the v1 behavior - ⏪ Major: make
response.json()
throw error instead of returning an empty object on 204 no-content respose (per spec; reverts behavior changed in v1.6.2) - Major: internal methods are no longer exposed
- Major: throw error when a
GET
orHEAD
Request is constructed with a non-null body (per spec) - ✨ Enhance: add
response.arrayBuffer()
(also applies to Requests) - ✨ Enhance: add experimental
response.blob()
(also applies to Requests) - ✨ Enhance:
URLSearchParams
is now accepted as a body - ✨ Enhance: wrap
response.json()
json parsing error asFetchError
- 🛠 Fix: fix Request and Response with
null
body
Headers class
- 🚚 Major: remove
headers.getAll()
; makeget()
return all headers delimited by commas (per spec) - ✨ Enhance: make Headers iterable
- ✨ Enhance: make Headers constructor accept an array of tuples
- ✨ Enhance: make sure header names and values are valid in HTTP
- 🛠 Fix: coerce Headers prototype function parameters to strings, where applicable
📚 Documentation
- ✨ Enhance: more comprehensive API docs
- ✨ Enhance: add a list of default headers in README