Set data format with WSMedia
It is important to set the correct MIME type for a Web service request or response. You can specify the data format via the WSMedia attribute.
For records and arrays in the message response the default MIME type can be JSON
(application/json
) or XML (application/xml
). The payload format is
chosen according to that specified in the Accept header received from the client using the Web
service.
In the example if the Accept header of the client expects XML, it returns XML, or JSON
if it expects JSON. The WSMedia
attribute can contain a comma-separated list of MIME types.
Example WSMedia with record type
TYPE addType RECORD
a INT,
b INT,
c INT
END RECORD
PUBLIC FUNCTION add_any(
a INTEGER ATTRIBUTES(WSParam),
b INTEGER ATTRIBUTES(WSParam) )
ATTRIBUTES (WSGet,
WSPath="/Add/{a}/{b}" )
RETURNS addType ATTRIBUTES(WSName="add",
WSMedia="application/json,application/xml")
DEFINE add addType
LET add.a = a
LET add.b = b
LET add.c = add(a,b)
RETURN add.*
END FUNCTION
Example WSMedia with image
For WSMedia
examples using images or files, see Example: upload a file in a multipart request.