Response

API ReferenceNetworkingResponse

Source


Response.STATUSES

Static property of
Response
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:

  • Response.OK,
  • Response.CREATED,
  • Response.ACCEPTED,
  • Response.NO_CONTENT,
  • Response.MOVED,
  • Response.FOUND,
  • Response.NOT_MODIFIED,
  • Response.TEMPORARY_REDIRECT,
  • Response.BAD_REQUEST,
  • Response.UNAUTHORIZED,
  • Response.PAYMENT_REQUIRED,
  • Response.FORBIDDEN,
  • Response.NOT_FOUND,
  • Response.CONFLICT,
  • Response.PRECONDITION_FAILED,
  • Response.UNSUPPORTED_MEDIA_TYPE,
  • Response.INTERNAL_SERVER_ERROR,
  • Response.NOT_IMPLEMENTED,
  • Response.SERVICE_UNAVAILABLE.
console.log(Networking.Response.OK);
console.log(Networking.Response.BAD_REQUEST);

Source


constructor()

Parameters
  • options — Object

Access it with:

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

Source


onSend()

Type
Signal

Called when the response has been sent.

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

Source


pending

Type
Boolean
Read Only

Indicates whether the response is not destroyed.

Source


request

Type
Networking.Request
Read Only

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

Source


status

Type
Integer
Default
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


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


headers

Type
Object

Source


cookies

Type
Object

Source


encoding

Type
String
Default
'utf-8'

Source


setHeader()

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

Source


send()

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


redirect()

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

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

Source


raise()

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


isSucceed()

Returns
Boolean

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

Source

results matching ""

    No results matching ""