Response

APINetworkingResponse

Source

Response.STATUSES

Type:
Array

Contains abstract codes used to describe the response type.

Each status corresponds to the HTTP numeral value. Check http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for more.

Contains:

console.log(Networking.Response.OK);
console.log(Networking.Response.BAD_REQUEST);

Source

Response::constructor(options)

Parameters:
  • options — Object

Access it with:

var Networking = require('networking');
var Response = Networking.Response;

Source

Response::onSend()

Type:
Signal

Called when the response has been sent.

res.onSend(function(){
    console.log("Response has been sent!");
});

Source

Response::pending

Type:
Boolean
Read Only

Indicates whether the response is not destroyed.

Source

Response::request

Type:
Networking.Request
Read Only

Refers to the [Request][networking/Request].

Source

Response::status

Type:
Integer
Default value:
Response.OK

Keeps a normalized code determined the response type.

It refers to one of the Response.STATUSES values.

res.status = Networking.Response.CREATED;
res.status = Networking.Response.PAYMENT_REQUIRED;

Source

Response::data

Type:
Any

Value sent to the client.

res.data = {items: ['superhero toy', 'book']};
res.data = new Error("Wrong order");
res.data = Document.fromJSON(...);

Source

Response::headers

Type:
Object

Source

Response::cookies

Type:
Object

Source

Response::encoding

Type:
String
Default value:
'utf-8'

Source

Response::setHeader(name, value)

Parameters:
  • name — String
  • value — String
Returns:
Response
res.setHeader('Location', '/redirect/to/url');

Source

Response::send(status, data)

Parameters:
  • status — Integeroptional
  • data — Anyoptional

This method calls the [onSend()][networking/Response::onSend()] signal.

res.onSend(function(){
    console.log("Response has been sent");
});

res.send(Networking.Response.OK, {user: 'Max', age: 43});

Source

Response::redirect(status, uri)

Parameters:
  • status — Integer= Response.FOUND
  • uri — String

The Response.FOUND status is typically used for temporary redirection. The Response.MOVED is a permanent redirection.

Source

Response::raise(error)

Parameters:
  • error — Any

Finishes the response with an error.

res.raise(new Networking.Response.Error("Login first"));
res.raise(new Networking.Response.Error(Networking.Response.UNAUTHORIZED, "Login first"));

Source

Response::isSucceed()

Returns:
Boolean

Returns true if the response status is in range from 200 to 299.

Source