import {SkygearResponse} from 'skygear-build/packages/skygear-core/lib/cloud/transport/common.js'
SkygearResponse
This is thin response object trying to provide a http.ServerResponse like interface for setting response headers and body.
Static Method Summary
Static Public Methods | ||
public static |
isInstance(obj: *): boolean Returns whether the specified object is a SkygearResponse. |
|
public static |
wrap(result: *): SkygearResponse Wrap response body into a SkygearResponse. |
Constructor Summary
Public Constructor | ||
public |
constructor(options: Object) Creates an instance of SkygearResponse. |
Member Summary
Public Members | ||
public |
body: string The HTTP body of the response. |
|
public |
headers: Object The HTTP headers of the response. |
|
public |
statusCode: number The HTTP status code of the response. |
Method Summary
Public Methods | ||
public |
getHeader(name: string): string Get a HTTP header from the response. |
|
public |
removeHeader(name: string) Remove a HTTP header from the response. |
|
public |
setHeader(name: string, value: string) Set a HTTP header to the response. |
|
public |
toResultJSON(): Object Convert the response to a result JSON that is suitable for plugin transport. |
|
public |
write(chunk: string) Write a chunk of data into the response. |
Static Public Methods
public static isInstance(obj: *): boolean source
Returns whether the specified object is a SkygearResponse.
Params:
Name | Type | Attribute | Description |
obj | * | object to be determined |
Return:
boolean | true if the object is a SkygearResponse |
public static wrap(result: *): SkygearResponse source
Wrap response body into a SkygearResponse.
If the specified value is a SkygearResponse, the same object will be returned.
Params:
Name | Type | Attribute | Description |
result | * | SkygearResponse or response body |
Public Constructors
public constructor(options: Object) source
Creates an instance of SkygearResponse.
Params:
Name | Type | Attribute | Description |
options | Object |
|
options to initialize the response |
options.statusCode | number |
|
HTTP status code of the response |
options.body | string |
|
HTTP response body |
options.headers | Object |
|
HTTP response headers |
Public Members
Public Methods
public getHeader(name: string): string source
Get a HTTP header from the response.
Params:
Name | Type | Attribute | Description |
name | string | HTTP header name |
Return:
string | HTTP header value |
public removeHeader(name: string) source
Remove a HTTP header from the response.
Params:
Name | Type | Attribute | Description |
name | string | HTTP header name |
public setHeader(name: string, value: string) source
Set a HTTP header to the response.
Params:
Name | Type | Attribute | Description |
name | string | HTTP header name |
|
value | string | HTTP header value |
public toResultJSON(): Object source
Convert the response to a result JSON that is suitable for plugin transport.
Return:
Object | result JSON for plugin transport |
public write(chunk: string) source
Write a chunk of data into the response. The chunk will be appended to any existing data in the response body.
Params:
Name | Type | Attribute | Description |
chunk | string | data to append to the response body |