Response
As default, API responses always an HTTP status code 200, and the response JSON format compatible with the GraphQL spec.
If you design a REST API and/or want to change the response defaults, you can configure the API response by setting the @response object in the JSON root object.
Data source
{
"@response": {
"alwaysOk": true,
"bodyOnSuccess": {"data": "%data%"},
"bodyOnError": {"errors": [{"message": "%message%"}]}
}
}
- @response.alwaysOk
- If this option is true, API responses always an HTTP status code 200, and if false, will return an error code in case of an error such as 404.
- @response.bodyOnSuccess
- Set the response JSON format for a success cases. And need a %data% placeholder to replace the result (or result set). This option is enable on a REST API.
- @response.bodyOnError
- Set the response JSON format for an error cases. A %message% placeholder is replace with an error message like "Resource not found". This option is enable on a REST API.
If you want the raw result (or result set) in the response body, just set the placeholder to body.
Data source
{
"@response": {
"bodyOnSuccess": "%data%",
"bodyOnError": "%message%"
}
}