-
-
Notifications
You must be signed in to change notification settings - Fork 0
response
Nathanaël Cherrier (CI) edited this page Aug 27, 2019
·
2 revisions
export class Response {
data?: any,
errorCode: number,
description: string|null
get contentType(): string
set contentType(contentType: string)
constructor(data: any, errorCode = 200, description: string|null = null)
setHeader(key: string, value: string): void
getHeader(key: string): string
send(httpResponse: HttpResponse): void
}
Response
is a wrapper for the NodeJS Reponse
object. It helps you build an HTTP response.
You can return Response
objects in controllers' actions. This is useful when you have to customize the reponse (status code, description...)
Initialize Response
instance with common params.
constructor(data: any, errorCode = 200, description: string|null = null)
-
data
: the data you want to return to the user -
errorCode
: an HTTP error code for the response. The default value is200
. -
description
: the response explaination. Give context about the response. It is commonly related toerrorCode
.
-
contentType
: indicate in what format is the request data (JSON
, brut text...) -
data
: the data you want to return to the user -
errorCode
: an HTTP error code for the response. The default value is200
. -
description
: the response explanation. Give context about the response. It is commonly related toerrorCode
.
Add/Update an entry in the header with a given key and value
setHeader(key: string, value: string): void
-
key
: the name of the header field. (for example,Accept
) -
value
: the value of the header field.
nothing
Get an entry in the header with a given key
getHeader(key: string): string
-
key
: the name of the header field. (for example,Accept
)
The value corresponding to the key
Apply modification on and execute an HTTP response
send(httpResponse: HttpResponse): void
-
httpResponse
: the HTTP response to update and execute
nothing