API Response Element
The API Response Element in Convoworks API Builder allows you to define the HTTP response returned by your server. This includes the HTTP status, headers, and body.
Properties
- Status: An integer value that defines the HTTP status code for the response. A successful HTTP request is indicated by 200. Other status codes can be used to represent different responses, such as 404 for Not Found or 500 for Server Error.
- Headers: Key-value pairs defining the headers of the HTTP response. The default header is 'Content-Type: application/json', but you can add more as per your application's requirements.
- Body: This field represents the raw response body. You can define the data you want to send in response to the API call here. It can contain a plain string (like JSON), but it can also be evaluated.
Body Field Examples
You can use expressions to dynamically generate the response body:
- Example 1: If you have a numeric variable, you can include it in a JSON object like so:
{"field": ${intval( myNumericValue)} }
- Example 2: If you have an array, you can convert it to a JSON string like so:
${json_encode( myArrayValue)}