REST in the cloud

A primer on RESTful APIs in the cloud

The key to proper use of the cloud by enterprise information technology (IT) organizations depends on the deployment and consumption of cloud-based web services such as application programming interfaces (APIs). This article explains what a Representational State Transfer (REST) API is, the structure of an API, how REST APIs interact with cloud providers' infrastructure, a sample REST API for the cloud, REST and software as a service (SaaS), REST and platform as a service (PaaS), and various use cases.

Share:

Steven C. Markey (steve@ncontrol-llc.com), Principal, nControl

Author photoSteve Markey is a consultant, adjunct professor, and the current president of the Delaware Valley (Greater Philadelphia) chapter of the Cloud Security Alliance (CSA). He holds multiple certifications and degrees and has more than 11 years of experience in the technology sector. Steve frequently presents on information security, information privacy, cloud computing, project management, e-discovery, and information governance.



11 March 2013

Also available in Chinese Russian

Introduction

Many consider APIs to be the best method for organizations to access services provided by cloud computing vendors. Cloud consumers use APIs as software interfaces to connect and consume resources in various ways, though the optimal or contemporary route is to use a RESTful protocol-based API. Read on to gain an understanding of what APIs are and how they are used—particularly when it comes to REST APIs and cloud computing services. This article provides several use cases that demonstrate how this technology is used in the real world.


API primer

APIs are software interfaces that optimize development of an application or service for data processing. Often developers can import or integrate APIs into an existing code library via header files. However, with the advent of web services, developers are creating APIs to couple the ability to publish or consume web-based services with third-party system software.

As technology has matured, technology companies and functions have moved—or at least have tried to move—to a service-oriented architecture (SOA) model. This model allows for the development of web services using object-oriented programming languages that developers can call and reuse as appropriate. The Google Maps API is an example of a web-based API that allows developers to call and consume this service as appropriate in their application or website.

Structure of an API

Developers need to follow best practices and standards to correctly develop, publish, and consume APIs. These best practices and standards rely upon a basic structure that is dictated by the programming language the API is built for, namely: Java™, Microsoft® .NET, Objective-C, JavaScript Object Notation (JSON), or Extensible Markup Language (XML). Figures 1 and 2 are examples of XML-based APIs.

Figure 1 is PAID's shipping API, which allows organizations to tie this functionality into their eCommerce sites.

Figure 1. API used for shipping and logistical purposes (graphic used with permission from AuctionInc)
API used for shipping and logistical purposes

Figure 2 is Instra's API, which allows organizations to connect directly to their domain registrar for infrastructure purposes.

Figure 2. API used for domain hosting purposes (graphic used with permission from Instra Corporation)
API used for domain hosting purposes

Beyond the programming language used, the API also needs to take into account the nature of the service itself. In other words, there are different rules to follow if the API is created for client-side versus server-side consumption.

Whether the API is built for client-side or server-side consumption, a reality for developers is that the service needs to be built for high performance and with secure processing in mind. Developers of client-side APIs naturally focus on the user interface, aesthetics, and the look and feel of the application. Developers of server-side APIs deal with enhanced functionality or services for the original application with function in mind. Regardless of where the API will be used, today's developers lean toward using RESTful APIs because of their flexibility and versatility.

REST APIs

RESTful APIs follow the SOA model and, therefore, are often used by web service-based software architectures via XML or JSON for integration purposes. This means that they are consumed via an Internet browser or by web servers. As mentioned before, RESTful APIs are a relatively new technology requiring developers to have a thorough knowledge of current Web 2.0 technologies. Therefore, many organizations lacking an impetus to update their technology stack may not have the option of using this offering. Examples of organizations that may not be focused on RESTful APIs these days would certainly overlap with those not looking to become cloud consumers. These may include law firms, higher education institutions, and nonprofit groups. However, RESTful APIs are a reality that is here to stay.

Technology has come full circle in the sense that the majority of processing and storage resources have been pushed away from the end device, much like the days when mainframes and dumb terminals were prevalent. This is due to globalization, an increasingly remote or mobile workforce, ubiquitous Internet connectivity, and the maturity of SOA and Web 2.0 technologies such as RESTful APIs. With the addition of cloud computing used for data processing tasks via APIs, this trend is moving toward critical mass.


Cloud computing and APIs

Cloud computing services by nature are distributed. So, the use of web-based RESTful APIs by consumers is a logical solution for the remote consumption of data processing services. And, when economic downturns, emerging markets, and lower barriers to entry for competitors are brought to mind, it is not hard to understand why there is a renewed focus on technology for competitive advantage.

REST APIs are essential as businesses try to gain or keep a foothold in their industries or markets while dealing with globalization, an increasingly remote or mobile workforce, and ubiquitous Internet connectivity. These realities have created vastly different end-user requirements that need to be satisfied. The cloud is helping businesses realize these new priorities. However, for an organization to properly use the cloud, the technology staff should understand the nuances of cloud computing, as well as some common use cases for using the cloud or cloud service provider (CSP) API solutions.

Cloud computing overview

With regard to RESTful APIs, some cloud service delivery models have more RESTful APIs than others, namely SaaS and PaaS models. These delivery models focus on delivering software solutions for consumers, while infrastructure-as-a-service (IaaS) focuses on infrastructure services (for example, compute or storage capabilities). Most RESTful APIs lean toward SaaS solutions, though there are numerous RESTful API solutions available for PaaS consumers as well.

PaaS models allow for the development of an application on top of an existing service (for example, database as a service, or DBaaS), while SaaS solutions focus on a specific application type. Examples of PaaS include Amazon Web Services (AWS) Relational Database Service (RDS) and Salesforce.com's Force.com offering. Examples of SaaS solutions include Zoho Writer and Microsoft Dynamics CRM.

While REST APIs are more prevalent in SaaS and PaaS solutions, there are RESTful APIs for IaaS solutions as well. Most of the major cloud vendors (AWS, Rackspace, and so on) offer RESTful APIs for managing and administrating their IaaS environments, which cloud brokers such as RightScale leverage for their instance monitoring dashboards.

Sample cloud REST APIs

This section covers several sample cloud-based RESTful APIs to help you better understand how CSPs publish their RESTful APIs for consumption by cloud consumers.

Listing 1 is a sample IaaS-based RESTful API from AWS S3 for Domain Name System (DNS) redirects (for example, redirecting bigblue.com to ibm.com). You can leverage this API within a Java, .NET, or XML-focused integrated development environment (IDE).

Listing 1. RESTful API example (from AWS Documentation)
HTTP/1.1 307 Temporary Redirect
Location: http://johnsmith.s3-gztb4pa9sq.amazonaws.com/photos/puppy.jpg?rk=e2c69a31
Content-Type: application/xml
Transfer-Encoding: chunked
Date: Fri, 12 Oct 2007 01:12:56 GMT
Server: AmazonS3

<?xml version="1.0" encoding="UTF-8"?>
<Error>
  <Code>TemporaryRedirect</Code>
  <Message>Please re-send this request to the specified temporary endpoint.
  Continue to use the original request endpoint for future requests.</Message>
  <Endpoint>johnsmith.s3-gztb4pa9sq.amazonaws.com</Endpoint>
</Error>

Listing 2 is an example of using Hypertext Markup Language (HTML) to call a RESTful API from Netflix for catalog searches. This solution is offered as a PaaS solution that you can use to create an application that calls the Netflix API for catalog searches. Use case examples include an entertainment dashboard or a brokerage service for gaming.

Listing 2. Calling Netflix's RESTful API via HTML (from Netflix API Programmer's Guide: Common Rest API Tasks)
<html>
<head><title>Simple Search Page</title></head>
<body>
…
<%
  //callback
  Response resp = null;
  Strong sTerm = request.getParameter("term"); ← Get search term
  if( sTerm != null ) {
   String sRequest = ← Build request
    DemoApp.getService().buildRequestURI("/catalog/titles?term="+sTerm);
    resp = DemoApp.getService().call(
		sRequest, Method.GET, null); 
  }
 %>
<table>
 <tr><form action="simplesearch.jsp"><td></td>
  <input type="text" name="term" />
  <input type="submit" /></form></tr>
<%
  if( resp != null ) {
   DomRepresentation rep = resp.getEntityAsDom();
   Document doc = rep.getDocument(); ← Get the response
   XPath xpath = XPathFactory.newInstance().newXPath();
   NodeList nodes = ← Evaluate the response
   (NodeList) xpath.evaluate(
                          "/catalog_titles/catalog_title", doc, XPathConstants.NODESET );
   for( int i=0, n=nodes.getLength(); i<n; i++ ) {
    Node node = nodes.item(i);
       Retrieve the data of interest:
       String sTitle = (String) xpath.evaluate(
                                         "title/@regular", node, XPathConstants.STRING );
	String sImage = (String) xpath.evaluate(
                                         "box_art/@large", node, XPathConstants.STRING );
    String sID = (String) xpath.evaluate( "id/text()", node, XPathConstants.STRING );
 …
   }
  }
%>
<tr><table>tr align="center">
 <img src="<%=sImage%>" /><br />
  <%=sTitle%><br />
  <form action="addToQueue.jsp">
   <input type="hidden" name="title_ref" value="<%=sID%>" />
   <input type="submit" value="ADD" />
  </form><br /></tr></table>
</tr>
…
</table></body></html>

Cloud and API use cases

There are various use cases for how cloud consumers leverage cloud-based RESTful API to their advantage. This section provides several examples of how organizations consume SaaS, PaaS, and IaaS RESTful APIs.

Google Maps Coordinate is a SaaS-based RESTful API service that you can use for a mobile workforce. An organization can leverage Google Maps Coordinate as is or in an aggregated fashion with other applications (called a mash-up) to route drivers and coordinate pickups and deliveries. Any business that requires a dispatcher may be able to use this service via tablets or smart phones for enhanced productivity.

While on the topic of productivity, organizations that have more experience and resources dedicated to application and system development will be happy to hear that Amazon's DBaaS (AWS RDS) platform supports RESTful APIs as well. This functionality allows developers to call, manage, and administer Oracle, Microsoft, and Amazon-based relational and non-relational database solutions without having to use a management console. Organizations who want to have more operational control from an operating system perspective can consider IaaS-based RESTful APIs.

For those consumers that use IaaS CSPs, rest assured that most provide RESTful APIs for this delivery model as well. IBM®, Fujitsu, Amazon, and others have led the way with this functionality. These services allow consumers and cloud brokers to monitor and automate the provisioning of services in a manner that is truly elastic and on-demand.


Conclusion

Cloud computing and RESTful APIs are upon us, and it behooves your organization to determine how to leverage these technologies for cost savings from a capital expenditure standpoint or enhanced processing. To do this, your organization has to embrace Web 2.0 or SOA technologies and some or all of the cloud delivery (SaaS, PaaS, IaaS) and deployment (public, private, hybrid, community) models. By securely embracing these new paradigms, your enterprise will experience enhanced levels of flexibility and adaptability.

Economic downturns, emerging markets, lower barriers to entry, globalization, an increasingly remote or mobile workforce, and ubiquitous Internet connectivity are the new reality. To compete and thrive in today's marketplace, your organization needs to leverage these new technologies as appropriate. Most firms can start by using the cloud and REST APIs.

Resources

Learn

Get products and technologies

  • Evaluate IBM products in the way that suits you best: Download a product trial, try a product online, use a product in a cloud environment, or spend a few hours in the SOA Sandbox learning how to implement Service Oriented Architecture efficiently.

Discuss

  • Get involved in the developerWorks Community. Connect with other developerWorks users while exploring the developer-driven blogs, forums, groups, and wikis.

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Cloud computing on developerWorks


  • Bluemix Developers Community

    Get samples, articles, product docs, and community resources to help build, deploy, and manage your cloud apps.

  • developerWorks Labs

    Experiment with new directions in software development.

  • DevOps Services

    Software development in the cloud. Register today to create a project.

  • Try SoftLayer Cloud

    Deploy public cloud instances in as few as 5 minutes. Try the SoftLayer public cloud instance for one month.

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Cloud computing
ArticleID=861098
ArticleTitle=REST in the cloud
publish-date=03112013