Permalink
Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
111 lines (74 sloc) 2.16 KB
layout title icon group
samples
REST Calls
fa-caret-right
simple

{{ page.title }}

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

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

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

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

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.