Displaying a list with REST API
This example builds a navigation list of locations, BIRT Gazetteer requests values from a data set from the world.data file. The following is a general overview of that process:
*Search for the world.data file by building a URI using the REST API.
*Append the authentication identifier to the end of the URI and send it to an iHub server.
*Extract the file id from the file search request.
*Use the file id to make a second REST API request that retrieves a specific data set from the world.data file.
*Parse the JSON response from the iHub server into a collection of name and value pairs, such as an iOS NSDictionary object or an Java JSONObject for Android.
*Retrieve from the collection of name and value pairs the names of continents, regions, and countries.
*Build the list view navigation of the application using these names.
An example of this process using Objective-C is shown in the following selected source code from BIRTMasterViewController.m:
NSString *fileId;
@try {
NSString *fileName = [NSString stringWithFormat:@"%@%@",DATA_OBJECT_FOLDER, @"world.Data"];
NSString *getUrl =[NSString stringWithFormat:[NSString stringWithFormat:@"%@%@",REST_API_URL, @"files?search=%@&authId=%@"],
[fileName stringByAddingPercentEscapesUsingEncoding :NSUTF8StringEncoding], self.authId];
 
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:getUrl]];
NSError *urlConnectionError;
NSURLResponse *urlResponse;
NSData *data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&urlResponse error:&urlConnectionError];
 
NSError *error;
NSDictionary* response = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
 
NSArray * responseArr = response[@"ItemList"][@"File"];
if (responseArr == nil || [responseArr count] == 0) {
[self showAlert:@"Unable to get the file"];
} else {
self.regionData = response[@"data"];
self.arrayOriginal=responseArr;
}...
The region data is then used to make a hierarchical list that is used to populate the UITableView in the MasterView.
See the source code for the complete example.