Add multiple Link values
A response needs to expose several related URLs under one Link header.
Express.js · Module
res.append() adds a value or values to an HTTP response header, creating the header when necessary. It returns the response object and supports string or array values.
res.append() adds one or more values to an HTTP response header. If the header does not exist, Express creates it; the method returns the response object so calls can be chained.
res.append(field [, value])| Name | Type | Description |
|---|---|---|
field | String | Name of the HTTP response header to append to. |
value | String | String[] | undefined | Value or values to append to the header. |
Response
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.append('Link', ['</docs>', '</status>']);
res.append('Warning', '199 Miscellaneous warning');
res.send('Headers added');
});
app.listen(3000);Adds multiple response headers before sending the response.
A response needs to expose several related URLs under one Link header.
A route must attach a cookie header before sending its body.
A handler needs to add a warning or other custom header without manually checking whether it exists.
res.append() adds the supplied value or values to the named HTTP response header. When the header is absent, Express creates it with the supplied value.
Follow-up: What types can the value have? It can be a string, an array of strings, or undefined.
The field identifies the response header, while value contains the value or values to append. Express accepts a string or an array for value.
Follow-up: How can several Link values be added? Pass an array containing each Link value.
The method returns the Response object. This permits continuing response handling or chaining other response methods after appending the header.
Follow-up: What ordering issue must be considered with res.set()? Calling res.set() afterward resets the header value previously established by res.append().
res.set()res.get()res.send()res.header()