Page MenuHomePhabricator

Prepare JSON response for consumption from Web2Cit monitor
Closed, ResolvedPublic

Description

As discussed with @Superzerocool today, prepare the Web2Cit-Server's JSON response for consumption from the Web2Cit-Monitor.

Currently, the API (when asked for a JSON response) sometimes returns an array (of path results), an object (with an error property), or just plain text. Make it always return an object with the following properties:

  • info, including the API version (T313722) and the revid of the configuration files used
  • data, with the array of path results formerly returned as root object (maybe inside a results or paths sub-property, to leave room for average score; T313758).
  • optional error, including an error object with nameand message properties, just like we do already for path-specific errors.

In the array of path results, make sure that for each field we always return the output, test and score properties, even if they are undefined. Convert undefined output response to an empty array.

Event Timeline

make sure that for each field we always return the output, test and score properties, even if they are undefined

JSON does not support undefined values. We will continue not returning these values if they are undefined.

diegodlh claimed this task.

Implemented in 89b9f932 and deployed.

Also added score properties to the overall data object, and to specific target and result objects.

Concerning whether to explicitly return test and score properties even if they are undefined: this cannot be done in JSON, as mentioned in my previous post. Remember these may be undefined if an expected output (test) has not been defined for one or more target fields. Or if the API has been called with tests=false. Something similar happens with revid properties of config files which do not exist (yet) or are corrupt.

We may consider returning null in these cases instead. For now, we continue returning undefined in these cases (i.e., skipping these properties from the JSON response).