Class: response
A utility for managing responses.
Constructors
new response()
new response():
response
Returns
Methods
accepted()
readonly
accepted(response
):Response
<any
,Record
<string
,any
>>
HTTP Created response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:80
addAttachment()
readonly
addAttachment(response
,filename
?):Response
<any
,Record
<string
,any
>>
Set "Content-Disposition"
header to attachment with optional filename
.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• filename?: string
The filename for the attachment.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:982
addCookie()
readonly
addCookie(response
,name
,value
,options
):Response
<any
,Record
<string
,any
>>
Set cookie name
to val
, with the given options
.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• name: string
The name of the cookie.
• value: string
The value of the cookie.
• options: CookieOptions
The cookie options.
Returns
Response
<any
, Record
<string
, any
>>
Example
// "Remember Me" for 15 minutes
response.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
// save as above
response.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
@readonly
Defined in
utilities/exports/ResponseUtil.ts:1056
addFile()
readonly
addFile(response
,path
,callback
?):void
Transfer the file at the given path
.
Automatically sets the Content-Type response header field.
The callback fn(err)
is invoked when the transfer is complete
or when an error occurs. Be sure to check response.headersSent
if you wish to attempt responding, as the header and some data
may have already been transferred.
Other options are passed along to send
.
Examples:
The following example illustrates how response.sendFile()
may
be used as an alternative for the static()
middleware for
dynamic situations. The code backing response.sendFile()
is actually
the same code, so HTTP cache support etc is identical.
application.get('/user/:uid/photos/:file', function(req, res){
var uid = req.params.uid
, file = req.params.file;
req.user.mayViewFilesFrom(uid, function(yes){
if (yes) {
response.sendFile('/uploads/' + uid + '/' + file);
} else {
response.send(403, 'Sorry! you cant see that.');
}
});
});
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• path: string
• callback?: Errback
Returns
void
Defined in
utilities/exports/ResponseUtil.ts:2002
addHeader()
readonly
addHeader(response
,field
,value
?):Response
<any
,Record
<string
,any
>>
Appends the specified value to the HTTP response header field.
If the header is not already set, it creates the header with the specified value.
The value parameter can be a string
or an array
.
Note: calling response.set()
after response.append()
will reset the previously-set header value.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• field: string
The HTTP response header field.
• value?: string
| string
[]
The value to the header.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:804
addLocation()
readonly
addLocation(response
,url
):Response
<any
,Record
<string
,any
>>
Set the location header to url. The given url can also be the name of a mapped url, for example by default express supports "back" which redirects to the Referrer or Referer headers or "/".
Examples:
response.location('/foo/bar').; response.location('http://example.com'); response.location('../login'); // /blog/post/1 -> /blog/login
Mounting:
When an application is mounted and response.location() is given a path that does not lead with "/" it becomes relative to the mount-point. For example if the application is mounted at "/blog", the following would become "/blog/login".
response.location('login');
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• url: string
The url for the location to be set to.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:911
addLocationHeader()
readonly
addLocationHeader(response
,url
):Response
<any
,Record
<string
,any
>>
Set the location header to url. The given url can also be the name of a mapped url, for example by default express supports "back" which redirects to the Referrer or Referer headers or "/".
Examples:
response.location('/foo/bar').; response.location('http://example.com'); response.location('../login'); // /blog/post/1 -> /blog/login
Mounting:
When an application is mounted and response.location() is given a path that does not lead with "/" it becomes relative to the mount-point. For example if the application is mounted at "/blog", the following would become "/blog/login".
response.location('login');
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• url: string
The url for the location to be set to.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:888
advancedDownload()
readonly
advancedDownload(response
,path
,filename
,options
,callback
?):void
Transfer the file at the given path as an attachment.
Optionally providing an alternate attachment filename
, and optional callback fn(err)
.
The callback is invoked when the data transfer is complete, or when an error has occurred.
Be sure to check response.headersSent
if you plan to respond.
The optional options argument passes through to the underlying response.sendFile()
call, and takes the exact same parameters.
This method uses response.sendfile()
.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• path: string
The target file path.
• filename: string
The file name for when the client downloads the file.
• options: DownloadOptions
The download options.
• callback?: Errback
The callback if an error occurs.
Returns
void
Defined in
utilities/exports/ResponseUtil.ts:1206
advancedRender()
readonly
advancedRender(response
,view
,options
?,callback
?):void
Render view
with the given options
and optional callback fn
.
When a callback function is given a response will not be made
automatically, otherwise a response of 200 and text/html is given.
Options:
cache
boolean hinting to the engine it should cachefilename
filename of the view being rendered
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• view: string
The file path of the view file to render.
• options?: object
• callback?
Optional callback to the render function.
Returns
void
Defined in
utilities/exports/ResponseUtil.ts:1694
alreadyReported()
readonly
alreadyReported(response
):Response
<any
,Record
<string
,any
>>
HTTP Already Reported response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:140
append()
readonly
append(response
,field
,value
?):Response
<any
,Record
<string
,any
>>
Appends the specified value to the HTTP response header field.
If the header is not already set, it creates the header with the specified value.
The value parameter can be a string
or an array
.
Note: calling response.set()
after response.append()
will reset the previously-set header value.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• field: string
The HTTP response header field.
• value?: string
| string
[]
The value to the header.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:761
appendHeader()
readonly
appendHeader(response
,field
,value
?):Response
<any
,Record
<string
,any
>>
Appends the specified value to the HTTP response header field.
If the header is not already set, it creates the header with the specified value.
The value parameter can be a string
or an array
.
Note: calling response.set()
after response.append()
will reset the previously-set header value.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• field: string
The HTTP response header field.
• value?: string
| string
[]
The value to the header.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:783
attach()
readonly
attach(response
,filename
?):Response
<any
,Record
<string
,any
>>
Set "Content-Disposition"
header to attachment with optional filename
.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• filename?: string
The filename for the attachment.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:946
attachFile()
readonly
attachFile(response
,filename
?):Response
<any
,Record
<string
,any
>>
Set "Content-Disposition"
header to attachment with optional filename
.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• filename?: string
The filename for the attachment.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:958
attachment()
readonly
attachment(response
,filename
?):Response
<any
,Record
<string
,any
>>
Set "Content-Disposition"
header to attachment with optional filename
.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• filename?: string
The filename for the attachment.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:1006
badGateway()
readonly
badGateway(response
):Response
<any
,Record
<string
,any
>>
HTTP Bad Gateway response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:552
badRequest()
readonly
badRequest(response
):Response
<any
,Record
<string
,any
>>
HTTP Bad Request response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:242
callbackedEnd()
readonly
callbackedEnd(response
,callback
?):Response
<any
,Record
<string
,any
>>
Calling the writable.end()
method signals that no more data will be written
to the Writable
. The optional chunk
and encoding
arguments allow one
final additional chunk of data to be written immediately before closing the
stream.
Calling the write
method after calling end
will raise an error.
// Write 'hello, ' and then end with 'world!'.
const fs = require('node:fs');
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• callback?
Callback for when the stream is finished.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:1318
chunkedEnd()
readonly
chunkedEnd(response
,chunk
,callback
?):Response
<any
,Record
<string
,any
>>
Calling the writable.end()
method signals that no more data will be written
to the Writable
. The optional chunk
and encoding
arguments allow one
final additional chunk of data to be written immediately before closing the
stream.
Calling the write
method after calling end
will raise an error.
// Write 'hello, ' and then end with 'world!'.
const fs = require('node:fs');
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• chunk: any
Optional data to write. For streams not operating in object mode, chunk
must be a string
, Buffer
,
TypedArray
or DataView
. For object mode streams, chunk
may be any JavaScript value other than null
.
• callback?
Callback for when the stream is finished.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:1347
clear()
readonly
clear(response
,name
,options
?):Response
<any
,Record
<string
,any
>>
Clear cookie name
.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• name: string
The target cookie.
• options?: CookieOptions
The target cookie options.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:1141
clearCookie()
readonly
clearCookie(response
,name
,options
?):Response
<any
,Record
<string
,any
>>
Clear cookie name
.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• name: string
The target cookie.
• options?: CookieOptions
The target cookie options.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:1123
code()
readonly
code(response
,code
):Response
<any
,Record
<string
,any
>>
Set the response HTTP status code to statusCode
and send its string representation as the response body.
Source: http://expressjs.com/4x/api.html#res.sendStatus
Examples:
response.sendStatus(200); // equivalent to response.status(200).send('OK')
response.sendStatus(403); // equivalent to response.status(403).send('Forbidden')
response.sendStatus(404); // equivalent to response.status(404).send('Not Found')
response.sendStatus(500); // equivalent to response.status(500).send('Internal Server Error')
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• code: number
The response status code.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:2046
conflict()
readonly
conflict(response
):Response
<any
,Record
<string
,any
>>
HTTP Request conflict response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:332
contentType()
readonly
contentType(response
,type
):Response
<any
,Record
<string
,any
>>
Set Content-Type response header with type
through mime.lookup()
when it does not contain "/", or set the Content-Type to type
otherwise.
Examples:
response.type('.html');
response.type('html');
response.type('json');
response.type('application/json');
response.type('png');
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• type: string
The response content type.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:2283
continue()
readonly
continue(response
):Response
<any
,Record
<string
,any
>>
HTTP CONTINUE response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:27
cookie()
readonly
cookie(response
,name
,value
,options
):Response
<any
,Record
<string
,any
>>
Set cookie name
to val
, with the given options
.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• name: string
The name of the cookie.
• value: string
The value of the cookie.
• options: CookieOptions
The cookie options.
Returns
Response
<any
, Record
<string
, any
>>
Example
// "Remember Me" for 15 minutes
response.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
// save as above
response.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
@readonly
Defined in
utilities/exports/ResponseUtil.ts:1083
created()
readonly
created(response
):Response
<any
,Record
<string
,any
>>
HTTP OK response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:70
deleteCookie()
readonly
deleteCookie(response
,name
,options
?):Response
<any
,Record
<string
,any
>>
Clear cookie name
.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• name: string
The target cookie.
• options?: CookieOptions
The target cookie options.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:1177
download()
readonly
download(response
,path
,callback
?):void
Transfer the file at the given path as an attachment.
Optionally providing an alternate attachment filename
, and optional callback fn(err)
.
The callback is invoked when the data transfer is complete, or when an error has occurred.
Be sure to check response.headersSent
if you plan to respond.
The optional options argument passes through to the underlying response.sendFile()
call, and takes the exact same parameters.
This method uses response.sendfile()
.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• path: string
The target file path.
• callback?: Errback
The callback if an error occurs.
Returns
void
Defined in
utilities/exports/ResponseUtil.ts:1261
earlyHints()
readonly
earlyHints(response
):Response
<any
,Record
<string
,any
>>
HTTP Early Hints response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:57
encodedEnd()
readonly
encodedEnd(response
,chunk
,encoding
,callback
?):Response
<any
,Record
<string
,any
>>
Calling the writable.end()
method signals that no more data will be written
to the Writable
. The optional chunk
and encoding
arguments allow one
final additional chunk of data to be written immediately before closing the
stream.
Calling the write
method after calling end
will raise an error.
// Write 'hello, ' and then end with 'world!'.
const fs = require('node:fs');
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• chunk: any
Optional data to write. For streams not operating in object mode, chunk
must be a string
, Buffer
,
TypedArray
or DataView
. For object mode streams, chunk
may be any JavaScript value other than null
.
• encoding: BufferEncoding
The encoding if chunk
is a string
• callback?
Callback for when the stream is finished.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:1379
end()
readonly
end(response
):Response
<any
,Record
<string
,any
>>
Calling the writable.end()
method signals that no more data will be written
to the Writable
. The optional chunk
and encoding
arguments allow one
final additional chunk of data to be written immediately before closing the
stream.
Calling the write
method after calling end
will raise an error.
// Write 'hello, ' and then end with 'world!'.
const fs = require('node:fs');
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:1290
expectationFailed()
readonly
expectationFailed(response
):Response
<any
,Record
<string
,any
>>
HTTP Expectation failure response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:411
failedDependency()
readonly
failedDependency(response
):Response
<any
,Record
<string
,any
>>
HTTP Dependency Failure response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:460
file()
readonly
file(response
,path
,callback
?):void
Transfer the file at the given path
.
Automatically sets the Content-Type response header field.
The callback fn(err)
is invoked when the transfer is complete
or when an error occurs. Be sure to check response.headersSent
if you wish to attempt responding, as the header and some data
may have already been transferred.
Other options are passed along to send
.
Examples:
The following example illustrates how response.sendFile()
may
be used as an alternative for the static()
middleware for
dynamic situations. The code backing response.sendFile()
is actually
the same code, so HTTP cache support etc is identical.
application.get('/user/:uid/photos/:file', function(req, res){
var uid = req.params.uid
, file = req.params.file;
req.user.mayViewFilesFrom(uid, function(yes){
if (yes) {
response.sendFile('/uploads/' + uid + '/' + file);
} else {
response.send(403, 'Sorry! you cant see that.');
}
});
});
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• path: string
• callback?: Errback
Returns
void
Defined in
utilities/exports/ResponseUtil.ts:1876
forbidden()
readonly
forbidden(response
):Response
<any
,Record
<string
,any
>>
HTTP Forbidden response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:272
format()
readonly
format(response
,obj
):Response
<any
,Record
<string
,any
>>
Respond to the Acceptable formats using an obj
of mime-type callbacks.
This method uses req.accepted
, an array of
acceptable types ordered by their quality values.
When "Accept" is not present the first callback
is invoked, otherwise the first match is used. When
no match is performed the server responds with
406 "Not Acceptable".
Content-Type is set for you, however if you choose
you may alter this within the callback using response.type()
or response.set('Content-Type', ...)
.
response.format({
'text/plain': function(){
response.send('hey');
},
'text/html': function(){
response.send('<p>hey</p>');
},
'appliation/json': function(){
response.send({ message: 'hey' });
}
});
In addition to canonicalized MIME types you may
also use extnames
mapped to these types:
response.format({
text: function(){
response.send('hey');
},
html: function(){
response.send('<p>hey</p>');
},
json: function(){
response.send({ message: 'hey' });
}
});
By default Express passes an Error
with a .status
of 406 to next(err)
if a match is not made. If you provide
a .default
callback it will be invoked
instead.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• obj: any
The object to be formatted.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:1447
formatObject()
readonly
formatObject(response
,obj
):Response
<any
,Record
<string
,any
>>
Respond to the Acceptable formats using an obj
of mime-type callbacks.
This method uses req.accepted
, an array of
acceptable types ordered by their quality values.
When "Accept" is not present the first callback
is invoked, otherwise the first match is used. When
no match is performed the server responds with
406 "Not Acceptable".
Content-Type is set for you, however if you choose
you may alter this within the callback using response.type()
or response.set('Content-Type', ...)
.
response.format({
'text/plain': function(){
response.send('hey');
},
'text/html': function(){
response.send('<p>hey</p>');
},
'appliation/json': function(){
response.send({ message: 'hey' });
}
});
In addition to canonicalized MIME types you may
also use extnames
mapped to these types:
response.format({
text: function(){
response.send('hey');
},
html: function(){
response.send('<p>hey</p>');
},
json: function(){
response.send({ message: 'hey' });
}
});
By default Express passes an Error
with a .status
of 406 to next(err)
if a match is not made. If you provide
a .default
callback it will be invoked
instead.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• obj: any
The object to be formatted.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:1510
found()
readonly
found(response
):Response
<any
,Record
<string
,any
>>
HTTP Found response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:181
gatewayTimeout()
readonly
gatewayTimeout(response
):Response
<any
,Record
<string
,any
>>
HTTP Gateway Timeout response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:572
get()
readonly
get(response
,field
):undefined
|string
Get value for header field
.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• field: string
The HTTP response header field.
Returns
undefined
| string
Defined in
utilities/exports/ResponseUtil.ts:743
getHeader()
readonly
getHeader(response
,field
):undefined
|string
Get value for header field
.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• field: string
The HTTP response header field.
Returns
undefined
| string
Defined in
utilities/exports/ResponseUtil.ts:718
gone()
readonly
gone(response
):Response
<any
,Record
<string
,any
>>
HTTP Gone response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:342
header()
readonly
header(response
,field
):undefined
|string
Get value for header field
.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• field: string
The HTTP response header field.
Returns
undefined
| string
Defined in
utilities/exports/ResponseUtil.ts:731
httpVersionNotSupported()
readonly
httpVersionNotSupported(response
):Response
<any
,Record
<string
,any
>>
HTTP Version Unsupported response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:582
imATeapot()
readonly
imATeapot(response
):Response
<any
,Record
<string
,any
>>
HTTP I'm A Teapot response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:421
imUsed()
readonly
imUsed(response
):Response
<any
,Record
<string
,any
>>
HTTP I'm Used response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:150
insufficientStorage()
readonly
insufficientStorage(response
):Response
<any
,Record
<string
,any
>>
HTTP Insufficient Storage response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:602
internalServerError()
readonly
internalServerError(response
):Response
<any
,Record
<string
,any
>>
HTTP Internal Server Error response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:532
json()
readonly
json(response
,obj
):Response
<any
,Record
<string
,any
>>
Send JSON response.
Examples:
response.json(null);
response.json({ user: 'tj' });
response.status(500).json('oh noes!');
response.status(404).json("I don't have that");
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• obj: any
The object to be sent.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:1531
jsonp()
readonly
jsonp(response
,obj
):Response
<any
,Record
<string
,any
>>
Send JSON response with JSONP callback support.
Examples:
response.jsonp(null);
response.jsonp({ user: 'tj' });
response.status(500).jsonp('oh noes!');
response.status(404).jsonp("I don't have that");
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• obj: any
The object to be sent.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:1552
lengthRequired()
readonly
lengthRequired(response
):Response
<any
,Record
<string
,any
>>
HTTP Length Required response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:351
link()
readonly
link(response
,links
):Response
<any
,Record
<string
,any
>>
Set Link header field with the given links
.
Examples:
response.links({
next: 'http://api.example.com/users?page=2',
last: 'http://api.example.com/users?page=5'
});
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• links: any
The links to be added to headers.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:827
linkHeaders()
readonly
linkHeaders(response
,links
):Response
<any
,Record
<string
,any
>>
Set Link header field with the given links
.
Examples:
response.links({
next: 'http://api.example.com/users?page=2',
last: 'http://api.example.com/users?page=5'
});
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• links: any
The links to be added to headers.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:865
links()
readonly
links(response
,links
):Response
<any
,Record
<string
,any
>>
Set Link header field with the given links
.
Examples:
response.links({
next: 'http://api.example.com/users?page=2',
last: 'http://api.example.com/users?page=5'
});
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• links: any
The links to be added to headers.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:846
location()
readonly
location(response
,url
):Response
<any
,Record
<string
,any
>>
Set the location header to url. The given url can also be the name of a mapped url, for example by default express supports "back" which redirects to the Referrer or Referer headers or "/".
Examples:
response.location('/foo/bar').; response.location('http://example.com'); response.location('../login'); // /blog/post/1 -> /blog/login
Mounting:
When an application is mounted and response.location() is given a path that does not lead with "/" it becomes relative to the mount-point. For example if the application is mounted at "/blog", the following would become "/blog/login".
response.location('login');
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• url: string
The url for the location to be set to.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:934
locked()
readonly
locked(response
):Response
<any
,Record
<string
,any
>>
HTTP Request Locked response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:451
loopDetected()
readonly
loopDetected(response
):Response
<any
,Record
<string
,any
>>
HTTP Loop Detected response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:612
methodNotAllowed()
readonly
methodNotAllowed(response
):Response
<any
,Record
<string
,any
>>
HTTP Method Not Allowed response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:292
misdirectedRequest()
readonly
misdirectedRequest(response
):Response
<any
,Record
<string
,any
>>
HTTP Misdirected response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:431
movedPermanently()
readonly
movedPermanently(response
):Response
<any
,Record
<string
,any
>>
HTTP Permanently Moved response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:171
multipleChoices()
readonly
multipleChoices(response
):Response
<any
,Record
<string
,any
>>
HTTP Multiple Choices response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:161
multiStatus()
readonly
multiStatus(response
):Response
<any
,Record
<string
,any
>>
HTTP Multi Status response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:130
namedDownload()
readonly
namedDownload(response
,path
,filename
,callback
?):void
Transfer the file at the given path as an attachment.
Optionally providing an alternate attachment filename
, and optional callback fn(err)
.
The callback is invoked when the data transfer is complete, or when an error has occurred.
Be sure to check response.headersSent
if you plan to respond.
The optional options argument passes through to the underlying response.sendFile()
call, and takes the exact same parameters.
This method uses response.sendfile()
.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
• path: string
The target file path.
• filename: string
The file name for when the client downloads the file.
• callback?: Errback
The callback if an error occurs.
Returns
void
Defined in
utilities/exports/ResponseUtil.ts:1235
networkAuthenticationRequired()
readonly
networkAuthenticationRequired(response
):Response
<any
,Record
<string
,any
>>
HTTP Network Authentication Required response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:632
noContent()
readonly
noContent(response
):Response
<any
,Record
<string
,any
>>
HTTP No Content response method.
Parameters
• response: Response
<any
, Record
<string
, any
>>
The ApplicationResponse
object from your route handler.
Returns
Response
<any
, Record
<string
, any
>>
Defined in
utilities/exports/ResponseUtil.ts:100