Defining service response
Service responses for endpoint services or messaging/task services differ significantly. Only endpoint services return a response to the calling party, whereas messaging or task services cannot respond to the caller since there is no known calling party.
Endpoint services response definition
An endpoint service can respond with either success or error status. Successful execution of the service can either return a JSON document which can contain the object(s) from a single model or object(s) from multiple different models, a file (e.g., image, video, pdf, audio file), an HTML response or redirection to a URL.
There are six main nodes that you can use to define the response in your services.
At the end of an endpoint service, either a success or error response node needs to be executed. If no response node runs, Altogic returns an error message to the calling party.
Return Success Response
As its name implies, this node returns a successful response with HTTP status code 200 to the calling party. The response body can be empty, a single object, a list of objects, or named object(s) from multiple different models or custom key-value pairs.
- If there is no additional input to the Return Success Response node, namely, only the trigger link point is connected, and there aren't any other input link points added to the node, then the service returns success with an empty response body.
- If there is only one additional input to the Return Success Response node, then the service returns success with the additional input value, either a single object or a list of objects. You can customize how the response will be returned using the Return preference option to return the object without the input link point name as its key in response JSON document or not. For example, if we have a service that returns user info for a given userId, then you can return this data either with a key or not.
- If there is more than one input link point connected to the Return Success Response node beside the trigger input link point, you can return all connected input link points. For example, if you have a service that returns both user information and orders of a user, then you can return this data using key-value pairs.
- In addition to returning the data of input link points connected to the "Return Success Response node," you can also return additional values specified as key-value pairs. For each key-value pair, you can specify the name and value as expressions. This provides you additional flexibility to customize your response.
Return File Response
This node provides a single file (either inline or as an attachment) as the service's response with HTTP status code 200 to the calling party. The "Return File Response" node has only one object input link point and accepts only a single "file" object.
Return HTML Response
Besides JSON response format, you can also return HTML responses to the calling parties with an HTTP response code of 200. This node can be useful in cases when you would like to generate HTML content for your applications. As an example a user clicks on an email validation link, Altogic performs the required activities to mark the user's email as validated and returns an HTML response that shows a successful email validation result.
Redirect to URL
This node sends a special redirect response to a request with a specific URL to redirect to with an HTTP response code of 302.
This is a general response node to return either a success or error response with a single object value as output. With this node you can specify the HTTP response code and return the values that are provided as input to the response input of this node.
Return Error Response
The Error Response node returns with HTTP status code 40x, which can be customized, to the calling party. The response body can be empty, a list of error messages, a single object, a list of objects, or named object(s) from multiple different models. **** The configuration of the response body of the Return Error Response node is the same as the "Return Success Response" described node.
Omitting specific fields in response
You can customize the return values for "Return Success Response" and "Return Error Response" nodes. For each object provided as input to these nodes, you can additionally omit fields. When you omit additional fields, those fields are not returned in the response body.
Messaging or Task services response definition
Both messaging or task services can respond with either success or error status. The responses from these services are primarily used for logging purposes. There are two main nodes that you can use to define the response in your messaging or task services. In case of errors, you can return the list of errors that occurred.