Community articleSending a GET request in JavaScript
Added by IBM contributorIBM on September 27, 2013
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

Here is sample code to send a GET request to the Domino® Data Service and read the response.
This particular request is a Database collection GET das901Create New Article. It is coded in server-side JavaScript™ for XPages.

// Establish connection with Domino database collection resource
var url = new"");
var = url.openConnection();
conn.setRequestProperty("Accept", "application/json");
if (conn.getResponseCode() == "200") {
	// Get the response
	var reader = new;
	var buffer = new java.lang.StringBuffer();
	var line = "";
	while ((line = reader.readLine()) != null) {
	// Create array from response
	var jsonarray = eval('(' + buffer + ')');
	// Get filenames and titles from Domino database collection resource
	// On XPage, requestScope.status is bound to a multi-line text control
	for (var i = 0; i < jsonarray.length; i++) {
		requestScope.status += jsonarray[i].@filepath + " - " + jsonarray[i].@title + "\n";
} else { // if connection fails
	requestScope.status = conn.getResponseCode() + " " + conn.getResponseMessage();

Explanatory notes:
  • For a GET request, establish a network connection using and set the Accept request property to application/json.
  • The response code should be 200 for a successful GET.
  • The expected response in this case is a JSON array as a string. This example produces a proper array by evaluating the string.
  • Each array element is an object with properties. This example gets the values for the @filepath and @title properties in each object.

Parent topic: Programming Domino Data Service