Accessing HTTP resources with External Service element
Visual Designer’s External Service element is a tool for making HTTP requests to external services and processessing their responses. This document focuses on the former. It explains its capabilities and describes how it can be used from Visual Designer’s UI. Currently ES client supports:
GET or POST request methods
JSON or web form content types
HTTP or HTTPS schemes
basic HTTP authentication
Here is a simple GET request with parameters:
By default, all requests use GET method. Note that name-value parameter is user defined. Such parameters are appended in the query when the request is made. It’s a good practice to keep parameters in their own fields and avoid putting them directly in the Service Url field. Here is what the actual data on the wire:
GET /services/simpleGetRequest.php?name=foo HTTP/1.1
HTTP/1.1 200 OK
Both Service Url and Value fields support variable expansion. That means that all $variables and references in them will be replaced by their actual value before the request is being made.
Here $firstname variable will be expanded to its actual content.
$firstname → name
Here is a simple POST request:
In order to access the advances features of the ES client you will need to click on the gear icon. Also notice the following:
You can switch the HTTP method used by using the Method drop down menu. Default is GET.
Either www form or json content types are supported. For common url-encoded request use www form.
Manually building the body of the request with ‘&’ and ‘=’ can often be a daunting and error-prone task. Check Automatically populate from service parameters to let Visual Designer build the request body from the Name/Value pairs you have defined.
Let’s see it in action:
POST /services/simplePostRequest.php HTTP/1.1
HTTP/1.1 200 OK
You can also provide the POST body manually if you want. For example:
Notice how we have removed the service parameters and provided the url-encoded body instead. In case the service parameters were still there, they would be ignored.
Using a JSON request body is not much different:
POSTing JSON can only be done by manually providing the JSON expression. You will just need to set the Content type to json and type the JSON expression.
Here is an example of JSON expression:
Note that double quotes are being used in the JSON expression. Visual Designer does not know about the json syntax and its types. It will just go for a search‘n’replace. You will need to make sure that a valid json expression will result at the end.
Visual Designer makes HTTP requests to your server to fetch your business logic instructions. Some users prefer to know which IP address the request fromis coming from in order to open up specific ports in a firewall. However, due to the fluid nature of our cloud architecture, we don’t have a set range of IPs that requests are sent from or know in advance what they will be so please use proper security credentials & authentication when using Visual Designer External Service by following the steps in the below section.
For services that are protected with basic http authentication the user credentials need also to be provided:
In case the external service fails with an HTTP error code a handler can be used. In order to set up the handler you will need to:
create a handler Visual Designer module
bind the ES component to this handler using ‘On Remote Error’ drop down menu
Here is a sample handler module labeled ‘Error announcement’:
You can find the ‘On Remote Error’ drop down menu at the bottom of the ES component. Here is how it should look like after binding it to the handler module: