HTTP Response
Data Service REST jobs come with automatic serialization into data formats commonly used with REST services: JSON, XML and CSV. (To use a different format or override automatic serialization, see Custom Serialization.)
Records flowing through any edge connected to a port on the Output component in REST Job will be automatically serialized.
When a CSV serialization format is used, only one Output port can be connected, as all data must use the same metadata. If your graph logic has multiple edges, route all records into a single edge first before serialization, e.g. using the SimpleGather, Concatenate or Merge components.
Data Service automatically sets a Content-type response header based on a serialization format configured for the endpoint. The header is set to the following values:
application/json for JSON serialization;
application/xml for XML serialization;
text/csv for CSV serialization;
application/octet-stream for custom serialization (we recommend you override this).
There are additional options available specifically for JSON serialization. These are included to simplify response parsing on the consumer side for common JSON responses:
Possible JSON configurations are:
Settings | Example | Note |
---|---|---|
Output format: JSON No additional settings. |
{ "Books" : [ { "Title" : "Moby Dick", "Year" : 1851 }, { "Title" : "Don Quixote", "Year" : 1605 } ] } |
Example assumes two incoming data records (shown in pipe-delimited format here): Title | Year Moby Dick | 1851 Don Quixote | 1605 Notice the top-level JSON object named books. The object name is identical to metadata on the output edge. Names of JSON attributes are derived from field names in record metadata. The array under the top-level object allows sending arbitrary number of records, while preserving valid JSON structure. |
Output format: JSON with Do not write metadata enabled. |
{ "Title" : "Moby Dick", "Year" : 1851 }, { "Title" : "Don Quixote", "Year" : 1605 } ] |
Omits the top-level JSON object. Useful when a service returns only one single type of record, i.e. when only a single Output port is connected. |
Output format: JSON. with Do not write metadata enabled, as well as Do not write top level array enabled. |
{ "Title" : "Moby Dick", "Year" : 1851 } |
Skips the top level array. Returned JSON contains a single object with CloverDX record fields as attributes. Can be used only for a single record produced on a single port. Use this settings for services returning only a single record. If enabled and multiple records arrive on the output edge, the Data Service execution terminates with an exception. |