Skip to main content link. Accesskey S
  • Help
  • IBM Logo
  • IBM Web Experience Factory wiki
  • All Wikis
  • All Forums
  • ANNOUNCEMENT: Wiki changed to read-only. READ MORE...
  • Home
  • Product Documentation
  • Community Articles
  • Learning Center
  • IBM Redbooks
  • API Documentation
Search
Community Articles > Web Experience Factory > Samples and Techniques for Web Experience Factory > Transforming the Results of a REST Service Call
  • Share Show Menu▼
  • Subscribe Show Menu▼

About the Original Author

Click to view profileIBM contributorThomas Dinger
Contribution Summary:
  • Articles authored: 9
  • Articles edited: 1
  • Comments Posted: 1

Recent articles by this author

Client-Side Application Samples for Web Experience Factory 8.5

Sample models demonstrating how to build client-side applications

Camera and Worklight Enable Samples for Web Experience Factory 8.5

Sample models demonstrating how to use the Camera and Worklight Enable builders

Getting Started with WEF 8.5 Worklight Support

This document provides information for setting up Worklight Android with IBM Web Experience Factory 8.5 to create a hybrid application.

Best Practices for Building Client-Side Applications with IBM Web Experience Factory

Order of Builder Calls in a Client Model Theme. Theme builder call(s) or imported model containing common theme(s) should be first. Client Application. The Client Application builder call should be after the theme, because It depends on the theme. It should not typically be imported from ...

A Sample Application using the CMIS Document Access Builder

This article and the accompanying sample explain how to use the new CMIS Document Access builder in IBM® Web Experience Factory Version 8.0 (hereafter called WEF or Experience Factory.) This sample includes three WEF models – standard provider and consumer models, along with a model containing ...
Community articleTransforming the Results of a REST Service Call
Added by IBM contributorThomas Dinger | Edited by IBM contributorThomas Dinger on July 18, 2011 | Version 10
expanded Abstract
collapsed Abstract
This sample shows how to use Transform builders to restructure and revise the values of XML data retrieved from a back-end server.
Tags: REST Service Call, transform, schema
ShowTable of Contents
HideTable of Contents
  • 1 Introduction
  • 2 REST Service Call builder
  • 3 Transform builders
The XML data retrieved from a back-end server is frequently not in the format needed by your WEF application. Sometimes the structure of the data needs to be changed; sometimes the values of the data need to be changed. This sample shows how to use transform builders to change both the structure and the values of the XML data.

Introduction


To run this sample in Web Experience Factory Designer, you will need to download the attached project ZIP fileexternal link, and import it into a WEF project. Once imported, the project should look like this:

Project Explorer
Figure 1. Project Explorer

The project has both a provider model and a consumer model. This is a best practice for WEF projects that access data from a back-end server. The provider model contains all of the builders associated with accessing the back-end data, including a Service Definition builder that exposes the service to the consumer model. The consumer model contains all of the builders associated with the user interface, including a Service Consumer builder that is associated with the service from the provider model. The builders we're interested in for this sample are in the provider model.

REST Service Call builder


In order to use data from a back-end server in a WEF application, you first need to know how to access the data. In this sample we will access a publicly accessible REST service -- an RSS feed from the Web Experience Factory Forum. The REST Service Call builder in the sample model contains the URL to the forum, and specifies a "threadId" parameter. The value for this parameter has has been left blank, which indicates that it is an input for this builder.

REST Service Call builder inputs
Figure 2. Inputs for the REST Service Call builder

So that it can generate the correct schema for the specified REST service, the REST Service Call builder needs information about how to access sample data. In this case, we will just specify the same REST service URL as before, and supply a known value for the "threadId" parameter.

REST Service Call builder schema inputs
Figure 3. Schema inputs for the REST Service Call builder

Running the consumer model (with no transform builders) will produce results that look like this:

Original REST Service Call results
Figure 4. REST Service Call builder results before transforming

Transform builders


To illustrate how the REST Service Call builder results can be modified using transform builders, we will use one transform builder to restructure the results schema. Then we will use a second transform builder to change the values. This is an example of transform "chaining" -- the results of the REST Service Call builder are used as the inputs to the first transform builder, and the results of the first transform builder are used as the inputs to the second transform builder.

The first transform builder in the chain is a Transform Map builder. This builder is used to map elements between schemas in schema-typed XML data. The first transform action in this sample maps the "rss/channel/items/item" elements from the REST Service Call builder results to "items/item" elements in the transformed results, copying the child elements. This action effectively removes the first two levels of the schema and copies all of the repeating items we're interested in. The second transform action maps the "rss/channel/items/item/creationDate" elements from the REST Service Call builder results to "items/item/creationTime" elements in the transformed results, copying the text. This action effectively adds a <creationTime> element with the same value as the <creationDate> element. The Transform Map builder also contains a Result Schema Preview section that displays the transformed results structure.

Transform Map builder inputs
Figure 5. Inputs to the Transform Map builder

The second transform builder in the chain is a Transform Modify builder. This builder is used to modify elements in schema-typed XML data. Note that the Target Operation input specifies the Transform Map builder -- this is how the transform chain is constructed. The first transform action in this builder modifies the value of the creationDate element to remove the day and time portions of the string. The second transform action modifies the value of the creationTime element to remove the day and date portions of the string. The third and fourth transform actions modify the value of the author element to add an IBM indicator for IBM employees.

Transform Modify builder inputs
Figure 6. Inputs to the Transform Modify builder

In addition to the REST Service Call builder, each transform builder generates a data service and a schema for the transformed results. Any of these data services can be specified as the Action to Call in the Service Operation builder, but to get the fully transformed results, the transform at the end of the chain should be specified. In this sample, that's the Transform Modify builder.

Service Operation builder inputs
Figure 7. Inputs for the Service Operation builder

Running the consumer model will produce results that look like this:

REST Service Call results, with restructured elements and revised values highlighted
Figure 8. REST Service Call builder results after transforming

The shaded area shows the changes made by the transforms. For each result item, the author value now specifies whether the author is an IBM employee, the creation date now contains only the date value, and a new creation time column has been added that contains only the time value.

expanded Attachments (9)
collapsed Attachments (9)
File TypeSizeFile NameCreated OnDelete file
image/gif 6 KB project explorer.gif 7/14/11, 9:25 PM
image/gif 8 KB RestServiceCall.gif 7/18/11, 3:02 PM
image/gif 7 KB RestServiceCall_Schema.gif 7/18/11, 3:02 PM
image/gif 6 KB original results.gif 7/14/11, 3:41 PM
image/gif 13 KB TransformMap.gif 7/18/11, 6:46 PM
image/gif 15 KB TransformModify.gif 7/18/11, 6:47 PM
image/gif 7 KB ServiceOperation.gif 7/18/11, 8:47 PM
image/gif 8 KB transformed results highlighted.gif 7/13/11, 9:02 PM
application/x-zip 5 KB transform_feed_data_sample.zip 7/12/11, 8:11 PM
expanded Versions (11)
collapsed Versions (11)
Version Comparison     
VersionDateChanged by              Summary of changes
11Jul 19, 2011, 4:30:55 PMThomas Dinger  IBM contributor
This version (10)Jul 18, 2011, 9:09:09 PMThomas Dinger  IBM contributor
8Jul 18, 2011, 6:57:42 PMThomas Dinger  IBM contributor
7Jul 18, 2011, 6:42:30 PMThomas Dinger  IBM contributor
6Jul 18, 2011, 4:29:25 PMThomas Dinger  IBM contributor
5Jul 18, 2011, 3:40:41 PMThomas Dinger  IBM contributor
4Jul 14, 2011, 9:29:30 PMThomas Dinger  IBM contributor
3Jul 14, 2011, 9:27:02 PMThomas Dinger  IBM contributor
2Jul 14, 2011, 3:53:33 PMThomas Dinger  IBM contributor
1Jul 14, 2011, 2:17:41 PMThomas Dinger  IBM contributor
1Jul 14, 2011, 2:17:15 PMThomas Dinger  IBM contributor
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedHelpAbout
  • IBM Collaboration Solutions wikis
  • IBM developerWorks
  • IBM Software support
  • Twitter LinkIBMSocialBizUX on Twitter
  • BlogsIBMSocialBizUX on Facebook
  • ForumsLotus product forums
  • BlogsIBM Social Business UX blog
  • Community LinkThe Social Lounge
  • Wiki Help
  • Forgot user name/password
  • Wiki design feedback
  • Content feedback
  • About the wiki
  • About IBM
  • Privacy
  • Accessibility
  • IBM Terms of use
  • Wiki terms of use