Home Reference Source
public class | source

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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
result *

SkygearResponse or response body

Return:

SkygearResponse (nullable: false)

a SkygearResponse

Public Constructors

public constructor(options: Object) source

Creates an instance of SkygearResponse.

Params:

NameTypeAttributeDescription
options Object
  • optional
  • default: {}

options to initialize the response

options.statusCode number
  • optional
  • default: 200

HTTP status code of the response

options.body string
  • optional
  • default: ''

HTTP response body

options.headers Object
  • optional
  • default: {}

HTTP response headers

Public Members

public body: string source

The HTTP body of the response.

public headers: Object source

The HTTP headers of the response.

public statusCode: number source

The HTTP status code of the response.

Public Methods

public getHeader(name: string): string source

Get a HTTP header from the response.

Params:

NameTypeAttributeDescription
name string

HTTP header name

Return:

string

HTTP header value

public removeHeader(name: string) source

Remove a HTTP header from the response.

Params:

NameTypeAttributeDescription
name string

HTTP header name

public setHeader(name: string, value: string) source

Set a HTTP header to the response.

Params:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
chunk string

data to append to the response body