The Headers Object: A Safer Way to Manage HTTP Headers

The `Headers` object is a specialized map for HTTP headers that handles sanitization for you. Use it with the Fetch API to build requests or read response headers. The footgun: headers from a `fetch()` response are immutable and will throw an error if you try.
Think of the `Headers` object as a specialized, safer map for HTTP headers, unlike a plain JavaScript object. It automatically normalizes names to lowercase and sanitizes values. It's the standard way to manage headers when using the Fetch API, both for creating custom requests and for reading headers from a server response. The common footgun is assuming all `Headers` objects are mutable; headers attached to a response from a `fetch()` call are read-only, and attempting to modify them with `set()` or `append()` will throw a `TypeError`.
Read the original → developer.mozilla.org
- #web apis
- #fetch
- #http
- #javascript
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.