Response Header
A Response header can be passed on any native reply
methods as the third parameter.
The headers can be constructed using Headers
API of the Fetch API.
Creating header
A header can be set using
const headers = new Headers();
headers.set("x-foo", "123");
// or
headers.append("x-foo", "world");
Adding header to response
When returning the response using reply.text()
or any other native response method you can pass the headers
as the third argument of the function. By default the header is just an empty instance of the Headers()
.
// an example
return reply.text("Hello World", 200, headers);
For details on using headers please refer to MDN Reference on Headers API