Module: libs/rest

libs/rest

indigoJS rest module is a simple yet powerful representation of your RESTful API. By specifying service:path in app.conf you can link to custom version to your REST API's or another service manager module.

Version:
  • 1.0

Example

conf/app.json { ... "service": { "path": null, "host": "localhost", "port": 443, "secure": true } ... }

Requires

  • module:http
  • module:https

Members

headersObject

Specified default header values in JSON responce object.

Methods

delete(callback, path, data, query)

The function requests are used to delete an entity.

Name Type Description
callback function

A callback function that is executed if the request completed.

path String

Canonical path of the router.

data Object optional

An object that is sent to the server with the request.

query Object optional

URL query parameters.

Example

require('indigojs').service.put(function(err, result, req, res) { ... }, '/routerBase/deletePath', {'id':123});

get(callback, path, data, query)

This function used to request a LIST of entities or to SHOW details for one entity.

Name Type Description
callback function

A callback function that is executed if the request completed.

path String

Canonical path of the router.

data Object optional

An object that is sent to the server with the request.

query Object optional

URL query parameters.

Example

require('indigojs').service.get(function(err, result, req, res) { ... }, '/routerBase/getPath', null, {'framework': 'indigojs'});

init(opts){Object}

Initializing server settings.

Name Type Description
opts Object

Defined default server configuration where host is IP Address or domain name, port server port number and secure communications protocol HTTP or HTTPS.

Returns:
Scope to the current instance.
Examples

require('indigojs').service.init();

require('indigojs').service.init({ host:'localhost', port: 80 });

patch(callback, path, data, query)

The function perform a partial update of an entity.

Name Type Description
callback function

A callback function that is executed if the request completed.

path String

Canonical path of the router.

data Object optional

An object that is sent to the server with the request.

query Object optional

URL query parameters.

Example

require('indigojs').service.patch(function(err, result, req, res) { ... }, '/routerBase/patchPath', {'id':123, 'key':'value'});

post(callback, path, data, query)

Executing HTTP POST requests contain their data in the body of the request.

Name Type Description
callback function

A callback function that is executed if the request completed.

path String

Canonical path of the router.

data Object optional

An object that is sent to the server with the request.

query Object optional

URL query parameters.

Example

require('indigojs').service.post(function(err, result, req, res) { ... }, '/routerBase/postPath', {'key':'value'});

put(callback, path, data, query)

The function sending request and translated as UPDATE or REPLACE an entity.

Name Type Description
callback function

A callback function that is executed if the request completed.

path String

Canonical path of the router.

data Object optional

An object that is sent to the server with the request.

query Object optional

URL query parameters.

Example

require('indigojs').service.put(function(err, result, req, res) { ... }, '/routerBase/putPath', {'id':123, 'key':'value'});

request(callback, method, path, data, query)

The inner function for building REST requests and executing from get/post/put/delete/patch functions.

Name Type Description
callback function

A callback function that is executed if the request completed.

method String

HTTP method GET/POST/PUT/DELETE/PATCH.

path String

Canonical path of the router.

data Object optional

An object that is sent to the server with the request.

query Object optional

URL query parameters.