WSMedia
Defines the data format of the REST message.
Syntax
WSMedia = " MIME-type [
,...]
"
WSMedia
is a comma-separated list of MIME types:- MIME-type is a supported media
type.
A media type (also known as Multipurpose Internet Mail Extensions (MIME) type) is an identifier used by the HTTP protocol to denote message content. The format is based on standards from the Internet Assigned Numbers Authority (IANA).
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 ATTRIBUTES()
clause of
variables and/or on input and output function parameters.
Accept
or
Content-Type
HTTP headers are set in requests and responses:- If the
Accept
orContent-Type
header is set, the GWS sets the data format accordingly provided the MIME type is listed inWSMedia
. If the MIME type is not listed, the GWS returns a 400 No matching Rest operation found error. - If the
Accept
orContent-Type
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 denoting type of message content.Tip:You can specify the format at runtime by calling the REST service engine com.WebServiceEngine.SetOption option, for details see Setting MIME type at runtime.
Example: WSMedia with record variable
In this sample record definition, the WSMedia
attribute is set to the list of
different MIME types it supports.
PUBLIC DEFINE myRecord RECORD
ATTRIBUTES (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.