REST Calls

Steps

  1. Create a project rest_calls.
  2. Then create a JavaScript service named get_call.js.
  3. Within the service code, enter the following content:

GET Call

1
2
3
4
5
6
7
8
9
10
11
var httpClient = require('http/v3/client');
var response = require('http/v3/response');

var httpResponse = httpClient.get('http://services.odata.org/V4/Northwind/Northwind.svc/');

response.println(httpResponse.statusMessage);
response.println(httpResponse.text);
response.flush();
response.close();

  1. Then create a JavaScript service named post_call.js.
  2. Within the service code, enter the following content:

POST Call

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var httpClient = require('http/v3/client');
var response = require('http/v3/response');
	
var bodyContent = JSON.stringify({
		'firstName': 'John',
		'lastName': 'Doe',
		'age': 24
	});
	
var httpResponse = httpClient.post('http://httpbin.org/post', {
	    text: bodyContent
	});
	
response.println(httpResponse.statusMessage);
response.println(httpResponse.text);
response.flush();
response.close();

  1. Then create a JavaScript service named put_call.js.
  2. Within the service code, enter the following content:

PUT Call

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var httpClient = require('http/v3/client');
var response = require('http/v3/response');
	
var bodyContent = JSON.stringify({
		'firstName': 'John',
		'lastName': 'Doe',
		'age': 24
	});
	
var httpResponse = httpClient.put('http://httpbin.org/post', {
	    text: bodyContent
	});
	
response.println(httpResponse.statusMessage);
response.println(httpResponse.text);
response.flush();
response.close();

  1. Then create a JavaScript service named delete_call.js.
  2. Within the service code, enter the following content:

DELETE Call

1
2
3
4
5
6
7
8
9
10
11
var httpClient = require('http/v3/client');
var response = require('http/v3/response');
	
var httpResponse = httpClient.delete('http://httpbin.org/delete');
	
response.println(httpResponse.statusMessage);
response.println(httpResponse.text);
response.flush();
response.close();


For more information, see the API documentation.

Edit