Download a large object in the response body

This example demonstrates how to send a large object in the message response body.

To transfer a large object (LOB) to a client, specify a return parameter using a TEXT or BYTE data type. The large object is returned in the response body.

Example: downloading a TEXT object

In this example:
  • The TEXT variable (t) is created to hold the file content and is located in memory.
  • The readFile() method reads the content of the text file (file3.txt) into the TEXT variable (t).
  • The TEXT variable (t) is transferred in the message body.
  • The INTEGER variable, defined as a return parameter with the WSHeader attribute, is transferred in the response header.
PUBLIC FUNCTION help3()
  ATTRIBUTES (WSGet,
              WSDescription="Download text to the client in a TEXT object",
              WSPath="/help/file3")
  RETURNS ( INTEGER ATTRIBUTE(WSHeader), TEXT )
    DEFINE t TEXT
    LOCATE t IN MEMORY
    CALL t.readFile("file3.txt")
    RETURN 3, t
END FUNCTION
Figure: Output of HTTP response

Sample output of HTTP response sending a file in the body
The header is given a default name ("rv0") at runtime. Use the WSName attribute to rename the header.
RETURNS (INTEGER ATTRIBUTE(WSHeader, WSName="MyHeader"), TEXT)