Nathan M. Andelin   October 2016

IBM i Modernization - The User Interface

(Part 5)

Say you've been tinkering with HTML, CSS, and JavaScript. Now you'd like to move on to requesting things from an IBM i server. How does that work? The short answer is that browsers send messages to the server that contain URLs (i.e. http://mydomain.com/give_me.ext).

When the IBM i HTTP server receives a message from a browser, it maps the URL to a "resource" that is available (hopefully) on the server. IBM i resources include static files and programs. Programs may forward requests to web application servers and comparable runtime environments.

Before we get into details pertaining to resources available on IBM i, we should first understand the types of data (and information) that browsers may send along with "requests".

Browsers may send, for example:

  • URL query-string parameters (i.e. ?user=Nathan).
  • Request Headers.
  • HTML form data.
  • Cookies.
  • Formatted streams (i.e. JSON & XML).
  • Attached files (documents, etc.).

Understanding the content that may be included in browser requests is a premise for understanding what may be required of IBM i frameworks and runtime environments in order to enable developers to handle them.

Query String Parameters

Query string parameters are a series of name=value pairs that are appended to URLs (i.e. http://mydomain.com?user=Nathan&environment=development.

The first name=value pair is preceded by a question mark "?". All name=value pairs thereafter are preceded by an ampersand symbol "&".

IBM i web application frameworks should include APIs that return the:

  • Number of query-string parameters passed.
  • Names and values, given their numeric index.
  • Value, given the name.

Request Headers

Request headers are name: value pairs. Delimiters are are slightly different than query-string parameters (colons & line feeds). They provide information that is used by the IBM i Apache based HTTP server. And they can be useful to developers too.

Here's an example of request headers sent from a browser:


Host: rd.radile.com
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: en-US,en;q=0.8
If-None-Match: "1d744-2bbf-53ecae2816500"-gzip
If-Modified-Since: Fri, 14 Oct 2016 03:33:08 GMT


The IBM i based Apache server stores request headers along with various HTTP server configuration settings in JOB environment variables, that can be accessed from programs.

IBM i web application frameworks should include APIs comparable to the ones listed for query-string parameters, except used for returning data and values pertaining to JOB environment variables.

HTML Form Data

HTML <form> input elements are the primary means of entering data in web applications. The IBM i Marketplace Survey, which was presented in Part 4 included a form that contained several input elements. Browsers format this data, again as name=value pairs when "forms" are submitted.

IBM i web application frameworks should include APIs comparable to the ones listed for query-string parameters, except used for returning data and values submitted on HTML forms.

Cookies

Standards provide an option for servers to generate small files known as "cookies", that are returned to browsers, and stored on client devices. Servers can set the storage time-frame (i.e. session, whatever).

Browsers return cookies, appended to requests, when the requested URL matches a "path" specified in the cookie.

IBM i web application frameworks should include APIs that can be used for generating cookies, in addition to retrieving values stored in them.

Formatted Streams

Browsers may send data, formatted as XML or JSON text streams. This may include hierarchically formatted data objects.

IBM i web application frameworks should include APIs that enable developers to parse and extract XML and JSON formatted data into program variables and data structures, along with APIs for storing such streams in the integrated file system (IFS) if needed.

Attached Files

Browsers are capable clients for document management systems; They can upload files, attached to requests.

IBM i web application frameworks should provide a simple utility, that might be used to store file attachments in the IFS.

What Triggers Browser Requests?

Browser requests may be triggered by:

  • Embedding references in HTML tags (i.e. <img src="look.jpg">).
  • Clicking hyperlinks.
  • Submitting HTML forms.
  • Running JavaScript statements.

When you embed references to resources in HTML tags, they trigger additional server requests to fetch them, normally when the page loads.

Click Hyperlink:

<a href="request.shtml">Click Me</a>

Submit HTML Form:

<form action="request.shtml">
...
</form>
...
document.forms[0].submit();

Assign new page location by using JavaScript:

location.href = 'request.shtml';
location.assign('request.shtml');
location.replace('request.shtml');
location.reload(true);

Browsers can send asynchronous (background) requests by using its xmlHTTPRequest object. I may cover that in a separate article.

Summary

In order for browsers to interact with a server (i.e. IBM i), they send requests, using URLs. Requests may include a variety of data, documents, and information.

Knowing the types of content that may be included in requests, helps evaluate IBM i web application frameworks. This article builds on information provided in Part 4.

Continued in Part 6.