|
| 1 | +--- |
| 2 | +title: Response Methods |
| 3 | +description: Reference table of all methods available on the lambda-api RESPONSE object. |
| 4 | +--- |
| 5 | + |
| 6 | +The [RESPONSE object](/docs/request-response/response-object) is used to send a response back to the API Gateway. All methods are chainable unless they trigger a response. |
| 7 | + |
| 8 | +| Method | Description | Guide | |
| 9 | +| ------ | ----------- | ----- | |
| 10 | +| `status(code)` | Sets the HTTP status code returned to API Gateway (defaults to `200`, or `500` on a thrown error) | [Sending responses](/docs/request-response/sending-responses) | |
| 11 | +| `sendStatus(code)` | Sets the status code and returns its string representation as the response body | [Sending responses](/docs/request-response/sending-responses) | |
| 12 | +| `send(body)` | Triggers the response, sending the contents through as-is | [Sending responses](/docs/request-response/sending-responses) | |
| 13 | +| `json(body)` | Sets `content-type` to `application/json` and runs `JSON.stringify()` on the body | [Sending responses](/docs/request-response/sending-responses) | |
| 14 | +| `jsonp(body)` | Like `json()` but wraps the result in a callback function for JSONP | [Sending responses](/docs/request-response/sending-responses) | |
| 15 | +| `html(body)` | Sets `content-type` to `text/html` and passes through the contents | [Sending responses](/docs/request-response/sending-responses) | |
| 16 | +| `type(type)` | Sets the `content-type` header based on a file extension or MIME type string | [Sending responses](/docs/request-response/sending-responses) | |
| 17 | +| `header(key, value [,append])` | Sets a response header; supports multi-value arrays and an optional append flag | [Headers and cookies](/docs/request-response/headers-and-cookies) | |
| 18 | +| `getHeader(key [,asArray])` | Retrieves a header value (case-insensitive); returns a `string` by default | [Headers and cookies](/docs/request-response/headers-and-cookies) | |
| 19 | +| `getHeaders()` | Retrieves the current header object with `array` values | [Headers and cookies](/docs/request-response/headers-and-cookies) | |
| 20 | +| `hasHeader(key)` | Returns a boolean indicating whether `key` exists (case-insensitive) | [Headers and cookies](/docs/request-response/headers-and-cookies) | |
| 21 | +| `removeHeader(key)` | Removes the header matching `key` (case-insensitive); chainable | [Headers and cookies](/docs/request-response/headers-and-cookies) | |
| 22 | +| `getLink(s3Path [, expires] [, callback])` | Returns a promise resolving to a signed S3 URL for the referenced file | [Headers and cookies](/docs/request-response/headers-and-cookies) | |
| 23 | +| `cookie(name, value [,options])` | Sets a cookie header; only sets the header (a sending method must be called) | [Headers and cookies](/docs/request-response/headers-and-cookies) | |
| 24 | +| `clearCookie(name [,options])` | Expires a cookie; only sets the header (a sending method must be called) | [Headers and cookies](/docs/request-response/headers-and-cookies) | |
| 25 | +| `location(path)` | Sets the `Location:` header from a single string argument (encoded before being set) | [Redirects and CORS](/docs/request-response/redirects-and-cors) | |
| 26 | +| `redirect([status,] path)` | Triggers a redirection and ends execution; status defaults to `302` | [Redirects and CORS](/docs/request-response/redirects-and-cors) | |
| 27 | +| `cors([options])` | Adds CORS headers to the response; an optional `options` object customizes defaults | [Redirects and CORS](/docs/request-response/redirects-and-cors) | |
| 28 | +| `error([code], message [,detail])` | Stops execution and returns an error message, optionally with a status code and detail | [Redirects and CORS](/docs/request-response/redirects-and-cors) | |
| 29 | +| `etag([boolean])` | Enables Etag generation; returns `304 Not Modified` on a matching `If-No-Match` | [Caching and ETags](/docs/request-response/caching-and-etags) | |
| 30 | +| `cache([age] [, private])` | Adds a `cache-control` header; chainable | [Caching and ETags](/docs/request-response/caching-and-etags) | |
| 31 | +| `modified(date)` | Adds a `last-modified` header (`true` for now, a `Date`, or a parseable string) | [Caching and ETags](/docs/request-response/caching-and-etags) | |
| 32 | +| `attachment([filename])` | Sets `content-disposition` to "attachment", optionally with a filename | [Files and downloads](/docs/request-response/files-and-downloads) | |
| 33 | +| `download(file [, filename] [, options] [, callback])` | Combines `attachment()` and `sendFile()` to prompt a file download | [Files and downloads](/docs/request-response/files-and-downloads) | |
| 34 | +| `sendFile(file [, options] [, callback])` | Sends a local file, S3 file reference, or `Buffer` to the client | [Files and downloads](/docs/request-response/files-and-downloads) | |
0 commit comments