REST Developers Guide PDF
REST Developers Guide PDF
Version 9.6
April 2014
This document applies to webMethods Integration Server Version 9.6 and to all subsequent releases.
Specifications contained herein are subject to change and these changes will be reported in subsequent release notes or new editions.
Copyright © 2010-2014 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or
its affiliates and/or their licensors.
The name Software AG and all Software AG product names are either trademarks or registered trademarks of Software AG and/or
Software AG USA Inc. and/or its subsidiaries and/or its affiliates and/or their licensors. Other company and product names mentioned
herein may be trademarks of their respective owners.
Detailed information on trademarks and patents owned by Software AG and/or its subsidiaries is located at
hp://documentation.softwareag.com/legal/.
Use of this software is subject to adherence to Software AG's licensing conditions and terms. These terms are part of the product
documentation, located at hp://documentation.softwareag.com/legal/ and/or in the root installation directory of the licensed product(s).
This software may include portions of third-party products. For third-party copyright notices and license terms, please refer to "License
Texts, Copyright Notices and Disclaimers of Third Party Products”. This document is part of the product documentation, located at
hp://documentation.softwareag.com/legal/ and/or in the root installation directory of the licensed product(s).
Table of Contents
Index................................................................................................................................................ 27
This guide is for developers using webMethods Integration Server to create REST
applications. This guide assumes basic knowledge of REST concepts and HTTP request
processing and familiarity with Software AG Designer and webMethods Integration
Server.
Document Conventions
Convention Description
Italic Identifies variables for which you must supply values specific to
your own situation or environment. Identifies new terms the first
time they occur in the text.
{} Indicates a set of choices from which you must choose one. Type
only the information inside the curly braces. Do not type the { }
symbols.
... Indicates that you can type multiple options of the same type.
Type only the information. Do not type the ellipsis (...).
Documentation Installation
You can download the product documentation using the Software AG Installer. The
documentation is downloaded to a central directory named _documentation in the main
installation directory (SoftwareAG by default).
Online Information
You can find additional information about Software AG products at the locations listed
below.
Overview
Representational State Transfer (REST) is an architectural style used to build distributed
hypermedia systems. The World Wide Web is the best known example of such a system.
The focus of REST is on resources rather than services. A resource is a representation of
an object or information. A resource can represent:
A single entity, like a coffee pot you want to purchase from an online shopping site.
A collection of entities, like records from a database.
Dynamic information, like real-time status updates from a monitoring site.
That is, resources are the entities or collections of entities in a distributed system that
you want to post or retrieve or take action on. In a REST style system, each resource is
identified by a universal resource identifier (URI).
Development of REST systems is defined by a series of constraints:
Clients and servers are separate.
Communication between clients and servers is stateless.
Clients can cache responses returned from servers.
There may be intermediate layers between the client and server.
Servers can supply code for the clients to execute.
Clients and servers remain loosely coupled by communicating through a uniform
interface.
The uniform interface is the key constraint that differentiates REST from other
architectural approaches. The characteristics of this interface are:
Requests identify resources.
Responses contain representations of those resources.
Clients manipulate resources through their representations.
Messages are self-descriptive.
The interface employs Hypermedia as the engine of application state (HATEOAS),
which enables the client to find other resources referenced in the response.
One strength of REST is that it leverages the well understood methods supported by
HTTP to describe what actions should be taken on a resource. To be REST-compliant,
an application must support the HTTP GET, POST, PUT, and DELETE methods.
Many applications use web browsers to interact with resources on the Internet. web
browsers, however, typically support only the HTTP GET and HTTP POST methods.
To get around this restriction, you can use Integration Server to build REST-compliant
applications that support all four methods.
Integration Server can be a REST server or a REST client. When Integration Server
acts as a REST server, it hosts an application that you write. The application includes
services that you write that instruct Integration Server to process some or all of the
HTTP GET, POST, PUT, and DELETE methods in request messages against resources.
When Integration Server acts as a REST client, it sends specially formaed requests to
the REST server.
Where... Is the...
More complex request messages can contain more explicit information about the
resource.
Here is a request to obtain a list of all topics contained in the database, and how
Integration Server would parse the request:
GET /rest/discussion/topic HTTP/1.1
Where... Is the...
Example 2
Here is a request to display information about topic number 3419, and how Integration
Server would parse the request:
GET /rest/discussion/topic/3419 HTTP/1.1
Where... Is...
Note: Integration Server assigns the first token after the folder(s)
to the $resourceID parameter. To determine whether a token
represents a folder or the $resourceID , Integration Server
looks in the current namespace for a folder that has the same
name as the token. If it does not find a folder with this name,
Integration Server assigns the token to the $resourceID variable.
In other words, the first token (after the directive) that does not
correspond to a folder becomes the $resourceID .
Example 3
Here is a request to display information about a particular comment, 17 for example,
and how Integration Server would parse the request:
Where... Is...
Example 4
Here is a request to display information contributed by participant Robertson in 2009
about topic 17, and how Integration Server would parse the request:
GET /rest/discussion/topic/3419/comment/17?year=2009&name=Robertson HTTP/1.1
Where... Are...
year and name Input variables that are specific to your application. Tokens
specified after the ? must be entered as name/value pairs. In
this example, year=2009 and name=Robertson narrow the focus
of the GET request to entries that participant Robertson added
to comment 17 in 2009.
Status Line
The status line consists of the HTTP version followed by a numeric status code and
a reason phrase. The reason phrase is a brief textual description of the status code.
Integration Server will always set the HTTP version to match the version of the client
that issued the request. You cannot change the HTTP version.
You can, however, use the pub.flow:setResponseCode service to set the status code and
reason phrase. For more information about this service, refer to the webMethods
Integration Server Built-In Services Reference. If you do not explicitly set the status
code, Integration Server will set it to 200 for successfully completed requests and an
appropriate error code for unsuccessful requests.
HTTP/1.1 defines all the legal status codes in Section hp://www.w3.org/Protocols/
rfc2616/rfc2616-sec10.html#sec10. Examine these codes to determine which are
appropriate for your application.
Header Fields
You can communicate information about the request and the response through header
fields in the HTTP response. Integration Server will generate some header fields, such as
Set-Cookie, WWW-Authenticate, Content-Type, Content-Length, and Connection. You
can use the pub.flow:setResponseHeader to set Content-Type and other header fields. For
more information about this service, refer to the webMethods Integration Server Built-In
Services Reference.
HTTP/1.1 defines the header fields that can appear in a response in three sections of RFC
2616: 4.5, 6.2, and 7.1. Examine these codes to determine which are appropriate for your
application.
Message Body
The message body usually contains a representation of the requested resource, one or
more URLs that satisfy the request, or both. In some cases, the message body should be
empty, as specified in RFC 2616, Section 4.3
You can use the pub.flow:setResponse service to explicitly set the message body. See the
webMethods Integration Server Built-In Services Reference for details. If you do not explicitly
set the message body, the output pipeline of the top-level service will be returned to the
client in the message body.
For more information about how Integration Server builds HTTP responses, refer to the
section that describes how Integration Server chooses content handlers in webMethods
Integration Server Administrator’s Guide.
Services
When you build a REST application on your Integration Server, you must include
services that correspond to the HTTP methods you want to provide for each resource.
These services must be named as follows:
Service Description
These services reside in folders on your Integration Server in a directory structure that
is specific to your application. For example, the Discussion application described above
might have the following structure as viewed from Software AG Designer:
In addition to the _get, _put, _post, and _delete services, you can also place a special service
named _default in one or more of the application folders. Integration Server executes
this service if a REST request specifies an HTTP method that is not represented by a
service in the folder. For example, suppose the folder contains the _get, _put, and _post
services, but no _delete service. If the client issues a DELETE request, Integration Server
will execute the _default service, and pass “DELETE” to it in the $hpMethod variable.
If a request specifies an HTTP request method that is not represented by a service in the
folder and there is no _defaultservice in the folder, the request fails with error “404 Not
Found” or “405 Method Not Allowed.” Integration Server issues 404 if the first token in
the URI does not exist in the namespace, or 405 if one or more tokens in the URI identify
elements in the namespace but the URI does not correctly identify a folder and a service
to execute.
Example 1
A resource’s folder contains the _get, _post, and _default services:
Example 2
A resource’s folder contains the _get, _put, and _delete services:
Configuration
There are a few things you can configure with respect to REST processing:
Name of the REST directive
If you want to allow clients to specify a name other than “rest” for the REST
directive, you can do so with the wa.server.RESTDirective configuration parameter.
For example, to allow clients to specify “process” for the REST directive, you would
change the property to the following:
watt.server.RESTDirective=process
With this seing, clients can specify “rest” or “process” for the REST directive. In the
following example, the two requests are equivalent:
METHOD /process/discussion/topic/9876 HTTP/1.1
Note, however, that if you use the invoke directive instead of the rest directive, you
cannot take advantage of these REST-specific features:
$resourceID pipeline variable
$path pipeline variable
_default service
General Information
Include the following general information about your application:
A list of resource types
In the sample Discussion application described above, resource types would be
discussion and topic.
The HTTP methods your application supports for each resource
In the sample Discussion application, the discussion resource supports GET, but the
topics resource supports DELETE, GET, POST, and PUT.
Which request header fields are required or optional and how your application
responds to them. For example, the Discussion application might specify the
following information to explain which header fields it accepts and how it responds
to them:
Response: If the request was valid, the Discussion application will respond with the
following:
HTTP/1.1 201 Created
Content-Length: 0
ETag: 32619
Location: http://host/discussion/topic/32619
Response: If the request was valid, the Discussion application will respond with the
following:
HTTP/1.1 200 OK
Content-Length: 0
Location: http://host/discussion/topic/36219?comment=2
C S
configuration 21 status line of response to REST client 16
converting an existing REST application 22
Symbols
D $httpMethod input variable 20
documentation $path input parameter 16
using effectively 5 $resourceID input parameter 15
documenting your REST application 24 _default service 20
_delete service 20
H _get service 20
header fields of response to REST client 17 _post service 20
HTTP request methods _put service 20
supported 10
I
invoke directive 22
M
message body of response to REST client 17
P
processing directives
invoke 22
rest 14, 22
R
request messages
format 14
response to REST client
header fields 17
message body 17
status line 16
REST application
directory structure 20
setting up on Integration Server 20
REST application services 20
rest directive 14
alternative name for 21
REST processing
input parameters 14
passing input to application services 14
request format from REST perspective 14