Programming proiv restful services

  

Web Services  

Request Header Properties

The following table consists of a list of properties that are available in the RESTfulRequestSSO. Some of these properties are defined by the calling client and may not be present in the RESTful request; hence marked as optional.

To access these properties, use the getHdrParameter method on the RESTfulRequestSSO.

Parameter Name

Description

Accept (optional)    

String that represents content type, expressed as MIME type, that the client is able to understand.

Accept-Encoding (optional)

String that represents content encoding, usually a compression algorithm, the client is able to understand.

Cookie (optional)          

String that contains stored HTTP cookies previously sent by the server with the Set-Cookie header. Note: The RestfulRequestSSO makes the cookies available through the getCookie method.

Host (optional)                

String that specifies the domain name of the server (for virtual hosting), and (optionally) the TCP port number on which the server is listening.

User-Agent

Contains a characteristic string that allows the network protocol peers to identify the application type, operating system, software vendor or software version of the requesting software user agent.

cookies          

Signifies as a SDO (Structured Data Object) that is an array of the cookies in the Cookie header. Each element in the array is an SDO with a ‘path’ string (the name of the cookie) and a ‘value‘ string. Note: This array may be empty if there are no cookies. To get a reference to this object you will need to use the getObject method with a path of ‘header/cookies’ as the getHdrParameter method will return the JSON string of the object.

mappedString

This string is a part of the calling URL that was identified as identifying the Restful Service that called the Restful task being executed. This will be the Path property in the Restful Service definition.

method         

String that represents a HTTP request method, value can be one of GET, PUT, POST or DELETE.

protocol        

This string is the HTTP request protocol; can be either HTTP or HTTPS.

referrer (optional)        

This string contains the address of the previous web page from which a link to the currently requested page was followed; it can be an empty string.

url                    

This string is the full URL used to access this RESTful Service.

urlPath          

This string is the part of the URL following the host port.

Response Header Properties

The following table consists of a list of properties that are available in the RESTfulResponseSSO. All header properties in the RESTfulResponseSSO header are added to the HTTP response header.

To set the header properties use the setHdrParameter method on the RESTfulResponseSSO.

Parameter Name

Description

cookies          

Signifies as a SDO (Structured Data Object) that is an array of the cookies in the Cookie header. Each element in the array is an SDO with a ‘path’ string (the name of the cookie) and a ‘value‘ string. Note: The array can be empty if there are no cookies. This array will be populated automatically by using the setCookie method of the RESTfulResponseSSO.

MIME Type

String that represents content-type, expressed as a MIME type, of the data in the response. If this is not set, the response will use the first request header "Accept Content Type" and if it is not available then the content type will be ‘text/plain’.

status             

This string is the HTTP status response code. If this is not set, the status code will be ‘200’ (OK).

Response Data

The response data is included in the response body property of the RESTfulResponseSSO. This property is an SDO defined by the user and is by default empty. There is also a property called ‘stringBody’ that is also user-defined and is a string that may be used as the response body.

If the response body is not empty, it is converted by the MIME Type (as mentioned in MIME Type) to the correct format to be sent as the HTTP response body. The available content-types for converting the response body are listed in the following table:

Content-Type

Description

application/json 

Converts the response body to a JSON string.

application/xml 

Converts the response body to an XML string.

text/plain

Converts the response body to a string.

If the response body is empty, the ‘stringBody’ string is used as the HTTP response body ignoring any conversion expected by the specified content-type. That means the user must format the ‘stringBody’ correctly for the specified MIME type. The user can specify any string based MIME type.

Example Logic for a Restful Service

The following are two examples of the PROIV logic for a simple RESTful service. In the first example, the value of the mappedString header in HTML format is returned and in the second example the value of the User-Agent header in the body object is returned as JSON response.

Example 1:

// return mappedString in HTML.

$path = 'mimeType'
$value = 'text/html'
RestfulResponseSSO.setHdrParameter(setProperty)

$path = 'mappedString'
$value = RestfulRequestSSO.getHdrParameter(getProperty)

$path = 'stringBody'
$value = '<html><h2>mappedString = ' + $value + '</h2></html>'
RestfulResponseSSO.setString(setProperty)

Example 2:

//return UserAgent in JSON.

$path = 'mimeType'
$value = 'application/json'
RestfulResponseSSO.setHdrParameter(setProperty)

$path = 'User-Agent'
$value = RestfulRequestSSO.getHdrParameter(getProperty)

$path = 'body/User-Agent'
RestfulResponseSSO.setString(setProperty)

 

Comment on this topic

Topic ID: 400048