Networking

APINetworking

This module cares about communication client-server and client internally.

Currently only the HTTP protocol is supported.

Access it with:

var Networking = require('networking');

Source

Networking::constructor(options)

Parameters:
  • options — Object

Options:

Source

Networking::onRequest(request, response)

Parameters:
  • request — Networking.Request
  • response — Networking.Response
Type:
Signal

Source

Networking::protocol

Type:
String
Read Only

Source

Networking::port

Type:
Integer
Read Only

Source

Networking::host

Type:
String
Read Only

Source

Networking::url

Type:
String
Read Only

URL path contains a protocol, port and a host.

It can be set manually if the external address is different. Otherwise it's created automatically.

Source

Networking::language

Type:
String
Read Only

Indicates the application language regarding to BCP47 (e.g. 'en', 'en-US').

Source

Networking::pendingRequests

Type:
List
Read Only

Networking::createHandler(options)

Parameters:
  • options — Object
Returns:
Networking.Handler

Use this method to create a new Networking.Handler.

app.networking.createHandler({
    method: 'get',
    uri: '/users/{name}',
    schema: new Schema({
        name: {
            type: 'string',
            min: 3
        },
    }),
    callback: function(req, res, next){
        res.raise(new Networking.Response.Error(Networking.Response.NOT_IMPLEMENTED));
    }
});

Source

Networking::createRequest(options)

Parameters:
  • options — Object|Networking.Request
Returns:
Networking.Request

The given options object corresponds to the Networking.Request properties.

Source

Networking::get(uri, onLoadEnd)

Parameters:
  • uri — String
  • onLoadEnd — Function
Returns:
Networking.Request

Source

Networking::post(uri, data, onLoadEnd)

Parameters:
  • uri — String
  • data — Anyoptional
  • onLoadEnd — Function
Returns:
Networking.Request

Source

Networking::put(uri, data, onLoadEnd)

Parameters:
  • uri — String
  • data — Anyoptional
  • onLoadEnd — Function
Returns:
Networking.Request

Source

Networking::delete(uri, data, onLoadEnd)

Parameters:
  • uri — String
  • data — Anyoptional
  • onLoadEnd — Function
Returns:
Networking.Request

Source

Networking::resolveRequest(request)

Parameters:
  • request — Networking.Request

Source

Networking::createLocalRequest(options)

Parameters:
  • options — Object|Networking.Request
Returns:
Networking.Request

Use this method to create a new [Request][networking/Request] and handle it.

The given options object corresponds to the [Request][networking/Request] properties.

Local and server requests are supported.

Local requests

app.networking.createRequest({
    uri: '/achievements/world_2',
    onLoadEnd: function(err, data){
        if (this.response.isSucceed()){
            console.log("Request has been loaded! Data: " + data);
        } else {
            console.log("Error: " + err);
        }
    }
});

Requests to the server

app.networking.createRequest({
    method: 'post',
    uri: 'http://server.domain/comments',
    data: {message: 'Great article! Like it.'},
    onLoadEnd: function(err, data){
        if (this.response.isSucceed()){
            console.log("Comment has been added!");
        }
    }
});

Source