To add additional headers to the HTTP responses, you can use the header
method of the Response
object.
Here's an example:
import { Response } from '@deepkit/http'; router.get('/', () => { const content = 'Hello World'; const contentType = 'text/plain'; return new Response(content, contentType) .header('X-Custom-Header', 'Custom Value'); });
In this example, the response will have an additional header called X-Custom-Header
with a value of Custom Value
. You can chain multiple header
calls to add multiple headers to the response.
HtmlResponse and JsonResponse extends the Response class, so you can use the header
method on them as well.
The Response
class also provides other useful methods for manipulating the response, like status
, contentType
, header
, headers
. Use autocomplete to see all available methods.