"responseOptions"
Configures the server to return a customized response
The "responseOptions"
property is an optional object that configures the server to return a customized response.
An API may add additional properties to
"responseOptions"
.jsonAction APIs should implement the
"binaryFormat"
and"numberFormat"
properties because JSON does not support binary data and JSON parsers often do not adequately handle large numbers.Use
"binaryFormat"
to control how binary data is embedded in JSON strings.Use
"numberFormat"
to control whether JSON numbers are rendered as digits or digits embedded in a string.Use
"omit"
to remove a property from a response, such as omitting"errorMessage"
.
The "numberFormat"
property is an optional, case-insensitive string enum. It defines the format of JSON numbers returned in a response. "number"
is the default value.
Tip
Returning numbers embedded in strings puts your application in charge of how numbers are processed. It ensures JSON parsers and programming languages will not convert numbers to a numeric representation that loses precision, introduces rounding errors, truncates values, or generates errors.
"number"
This setting is most efficient because it causes the server to return numeric values as JSON numbers, such as
-1.23
.JSON numbers are base-ten numbers that may have any number of digits. Large numbers, such as
18446744073709551616.000144722494
are known to cause problems with JSON parsers and some programming languages, such as JavaScript. This is because they use IEEE floating point numbers, which have binary rounding errors and a limited range.
"string"
This returns the server to embed numeric values in JSON strings, such as
"18446744073709551616.000144722494"
.This is slightly less efficient because it includes two extra double quote characters.
When omitted or set to
null
,numberFormat
defaults to"number"
.
The "omit"
property is an optional array or strings that contain the name of a JSON property (not a JSON path) that the server should omit from the JSON response. It allows a client to remove jsonAction properties from a response that it does not want.
"omit"
reduces the amount of data transferred from server to client and minimizes parsing overhead.Top-level jsonAction properties can be removed by simply including the property name in the array, such as
"errorMessage"
.jsonAction properties inside
"debugInfo"
can be removed by referencing their JSON path, such as"debugInfo.request"
and"debugInfo.warnings"
.Properties inside
"result"
can be removed by referencing their JSON path — for example, if an API returns an"extraData"
property in"result"
, it can be removed by specifying"omit": [ "result.extraData" ]
.A server requires processing to remove properties from a response; thus, the processing cost of removing properties should be weighed against the network cost of transmitting properties.