The Headers interface is part of the Fetch API. It allows you create and manipulate the HTTP headers of request and response resources of fetch().
Constructor Jump to heading#The Header() constructor creates a new Header
instance.
let headers = new Headers(init);
Parameters Jump to heading# name type optional description init Headers
/ { [key: string]: string }
true
The init option lets you initialize the headers object with an existing Headers
or an object literal.
The return type of the constructor is a Headers
instance.
append(name: string, value: string)
Appends a header (overwrites existing one) to the Headers object. delete(name: string)
Deletes a header from the Headers object. set(name: string, value: string)
Create a new header in the Headers object. get(name: string)
Get the value of the header in the Headers object. has(name: string)
Check if the header exists in the Headers objects. entries()
Get the headers as key-value pair. The result is iterable. keys()
Get all the keys of the Headers object. The result is iterable. Example Jump to heading#
const myHeaders = new Headers({
accept: "application/json",
});
myHeaders.append("user-agent", "Deno Deploy");
for (const [key, value] of myHeaders.entries()) {
console.log(key, value);
}
const request = new Request("https://api.github.com/users/denoland", {
method: "POST",
headers: myHeaders,
});
Did you find what you needed?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4