Skip to content

Instantly share code, notes, and snippets.

@shawngiese
Last active August 29, 2015 14:09
Show Gist options
  • Select an option

  • Save shawngiese/d359161c5ab8183a5150 to your computer and use it in GitHub Desktop.

Select an option

Save shawngiese/d359161c5ab8183a5150 to your computer and use it in GitHub Desktop.
Using RESTful queries to extract data for display in an HTML table
<!doctype html>
<html>
<head>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<style type="text/css">
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<script type="text/javascript" language="JavaScript">
var user = "gazetteer";
var pass = "Demo1234"
var uriLogin = "http://restapitest.actuate.com:5000/ihub/v1/login";
var uriSearch = "http://restapitest.actuate.com:5000/ihub/v1/files";
var uriData = "http://restapitest.actuate.com:5000/ihub/v1/dataobject/";
var auth = "";
var fileid = "";
$.post(uriLogin, {"username" : user, "password" : pass}, function(data) {searchFile(data)})
function searchFile(result) {
auth = result.AuthId;
var search = uriSearch + "?search=%2FResources%2FClassic%20Models.data&authId=" + auth;
$.getJSON( search, function(response){getData(response)});
}
function getData(result) {
fileid = result.ItemList.File[0].Id;
var search = uriData + fileid + "/Customers?authId=" + auth;
$.getJSON( search, function(response){buildTable(response)});
}
function buildTable(result) {
$.each(result.data, function(i, item) {
var $tr = $('<tr>').append(
$('<td>').text(item.CUSTOMERNUMBER),
$('<td>').text(item.CUSTOMERNAME),
$('<td>').text(item.CITY),
$('<td>').text(item.POSTALCODE),
$('<td>').text(item.COUNTRY)
).appendTo('#records');
});
};
</script>
<body>
<table id="records" style="width:100%">
<tr>
<th>ID</th>
<th>Customer</th>
<th>City</th>
<th>ZipCode</th>
<th>Country</th>
</tr>
<tr></tr>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment