Networking

API ReferenceNetworking

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


constructor()

Parameters
  • options — Object

Options:

  • allowAllOrigins determines whether Access-Control-Allow-Origin should return wildcard, false by default

Source


onRequest()

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

Source


protocol

Type
String
Read Only

Source


port

Type
Integer
Read Only

Source


host

Type
String
Read Only

Source


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


language

Type
String
Read Only

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

Source


pendingRequests

Type
List
Read Only

createHandler()

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


createRequest()

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

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

Source


get()

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

Source


post()

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

Source


put()

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

Source


delete()

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

Source


resolveRequest()

Parameters
  • request — Networking.Request

Source


createLocalRequest()

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

results matching ""

    No results matching ""