WSMedia

Defines the data format of the REST message.

Syntax

WSMedia = " MIME-type [,...]"
Where WSMedia is a comma-separated list of MIME types:
  1. MIME-type is a supported data format type.

Usage

You use this attribute to define the supported data format of the message. You set the WSMedia attribute in the ATTRIBUTE() clause of variables and/or on input and output function parameters.

Example WSMedia with record variable

In this example a record is defined with a list of MIME types with WSMedia to allow the function handle different formats. The payload format is chosen according to that specified in the Accept header received from the client using the Web service.

PUBLIC DEFINE myRecord RECORD
  ATTRIBUTE (WSMedia=
    "application/json, application/xml, application/x-www-form-urlencoded")
    a INTEGER,
    b FLOAT,
    c STRING
END RECORD
Table 1 outlines the data formats supported via the WSMedia attribute with corresponding default data types where applicable:
Table 1. Supported MIME types
MIME type Default data type
application/json Record and array
application/xml Record and array
application/x-www-urlencoded Record (only)
text/plain Simpletype
application/octet-stream BYTE
image/* No default type

The actual format is chosen according to that specified in the Accept or Content-Type headers of HTTP requests and responses. See the example in WSContext.

There is an order of precedence that defaults to the first MIME type listed in WSMedia when the Accept or Content-Type header is not present in the request. The format chosen can also depend on the data type used, for defaults, see Table 1.

WSMedia and file attachments

If a file is to be attached, you can handle this through a parameter with a WSAttachment and a WSMedia attribute. The REST engine is designed to accept the parameter value then as a path to a file to be attached. For instance, if the file is an image, it is defined with a wildcard to allow for all image types:
input STRING ATTRIBUTE (WSAttachment, WSMedia="image/*") 

WSMedia is an optional attribute.