cla/ws - Webservice namespace

This namespace holds Clarive webservice call management and is useful for writting webservice rules that listens for incoming calls on a Clarive URL.

For every webservice rule, the developer needs to cater to a consumer, which is the user that makes the call to the webservice.


Returns the request object, with the following values:


Returns the request path arguments broken down into an Array.

var ws = require("cla/ws");
var req = ws.request();
var args = req.args();
for( var i=0; i<args.length; i++) {
    print( args[i] );

For instance, if the rule was invoked with the URL http://clariveurl/rule/json/myrule/path1/path2, the req.args() will return the array ['path1','path2'].


Returns the request body.

var ws = require("cla/ws");
var req = ws.request();
print( req.body() );  // the body can be a huge text string


Returns the request headers as an object. If the header parameters is sent, returns only the value for that given header.

var ws = require("cla/ws");
var req = ws.request();
print( req.headers('accept-language') );

Some common headers one may get from a browser call:

How to send headers (myheader and another) with a curl command call:

curl -Hmyheader=123 -Hanother=bar http://clariveurl/rule/json/myrule


Returns the request query parameters.

var ws = require("cla/ws");
var req = ws.request();
var fooParam = req.params('foo');  // in case this was called http://.../?foo=bar


Returns the expected request format by the consumer.

Usually this format should be transparent to the developer, but it maybe useful when returning specifically built responses.


The full URL of the request.

var ws = require("cla/ws");
var req = ws.request();
print( req.url() );   // something like: http://clariveurl/rule/json/myrule


Manipulate the webservice response values and options.

var ws = require("cla/ws");
var res = ws.response();,value)

Sets a key-value pair in a hashed (object) response data.

This is useful for returning JSON formats for webservice-like consumers.

var ws = require("cla/ws");
var res = ws.response();"foo", 1234);"bar", { xx: 10, yy: [1,2,100] });


The response body let's you freely define what text will be in the content body.

var ws = require("cla/ws");
var res = ws.response();

Important: remember that the client expects a different output format depending on the request URL: json, yaml, raw and soap. So make sure that the response follows what the requester is expecting when setting the res.body() directly.

Setting a response body will erase all previous key-value pairs that were set before.


Let the developer set the response status code.