SDN Controller Programming Guide

173
Figure 57 Sample Application View
GUI-Specific REST API
As seen previously the SKI framework uses JavaScript [40] as the underlying technology to create
Dynamic-HTML based views. Such dynamism comes from logic executed at the SDN Controller or
WEB server from the JavaScript point of view. The SKI framework integrates the jQuery [42] tool
which allows for the execution of asynchronous HTTP requests. jQuery encapsulates AJAX [43] to
achieve asynchronous calls: AJAX is the art of exchanging data with a server, and updating parts
of a web page, without reloading the whole page.
Use jQuery to connect to the server to retrieve information via HTTP request and HTTP responses.
RESTful web services [2] [1] was inspired by HTTP; as a result, REST can be used wherever HTTP
can. A RESTful web API (also called a RESTful web service) is a web API implemented using HTTP
and REST principles. Thus, use REST APIs to attend requests coming from the user interface.
The sample application already contains a module (hm-rs) for the RESTful Web Services that
expose to the outside world functionality provided by the sample application; however this
functionality refers to the applications domain model or business logic. Besides the domain model
functionality, a view normally has requirements that are specific to presentation logic (For example
a view could call the server to retrieve a catalog of pictures related to an item). It is not desired to
pollute the RESTful web services from hm-rs module with presentation logic specific methods.
Therefore, it’s considered a good practice creating GUI-specific REST APIs in the hm-ui module.
Similarly to the hm-rs module, in order to implement REST web services the module needs to
declare some dependencies; open the hm-ui/pom.xml file and add the XML extract from the
Creating Domain Service Resource (REST Interface of Business Logic Service) on page 137 under
the “REST Module Dependencies listing and the RESTful Web Services Unit Test on page 146
under “Resource Test Dependencies listing, to the <dependencies> node (Remove any
duplicates). After updating the POM file update the Eclipse project dependencies (see Updating
Project Dependencies on page 115).
The following SwitchViewResource.java listing shows how to create the Switch View REST API
named SwitchViewResource. The SwitchViewResource.java listing shows an extract of the resource.
To use JSON encoding see JSON Encoding on page 152. To write unit test follow the instructions
from RESTful Web Services Unit Test on page 146.