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 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
WSMedia
attribute with corresponding
default data types where applicable: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
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.