WSMedia
Defines the data format of the REST message.
Syntax
WSMedia = " MIME-type [,...]"
Where
WSMedia
is a comma-separated list of MIME types:- MIME-type is a supported media type.
WSMedia
is an optional attribute.
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.
The GWS chooses the format based on whether the
Accept
or
Content-Type
HTTP headers are set in requests and responses:- If the header is set, the GWS sets the data format accordingly provided the MIME type is listed
in
WSMedia
. If the MIME type is not listed, the GWS returns a 400 No matching Rest operation found error. - If the header is not set, the GWS defaults to:
- Selecting the first MIME type listed in
WSMedia
. - Or depending on the data type, selecting the appropriate default format for the type.
- Selecting the first MIME type listed in
- If
WSMedia
is not set, the GWS defaults to selecting the appropriate default format for the type.Note: You can specify the format at runtime by calling the REST service engine option, for details see Setting MIME type at runtime.
Example: WSMedia with record variable
The example defines a record with a list of MIME types with WSMedia
that allows
the function handle different formats.
PUBLIC DEFINE myRecord RECORD
ATTRIBUTE (WSMedia=
"application/json, application/xml, application/x-www-form-urlencoded")
a INTEGER,
b FLOAT,
c STRING
END RECORD
WSMedia and file attachments
If a file is to be attached, you can handle this through a parameter with a WSAttachment and the WSMedia
attribute. For details, see Attach files with WSAttachment and WSMedia.