Quantcast
Channel: Telestax Docs Online
Viewing all articles
Browse latest Browse all 94

Making HTTP requests with External Service client

$
0
0

RestComm Visual Designer’s External Service element is a tool for makiing 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 RVD’s UI.

Currently ES client supports:

  • GET or POST request methods
  • JSON or web form content types
  • HTTP or HTTPS schemes
  • basic HTTP authentication

A Simple GET request

Here is a simple GET request with parameters:

Selection_069

 

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:

Request 

GET /services/simpleGetRequest.php?name=foo HTTP/1.1

Host: localhost

Response:
HTTP/1.1 200 OK

A note on Variable expansion

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.

For example:

Selection_071

 

Here $firstname variable will be expanded to its actual content.

$firstname → name

 

POSTing web forms

Here is a simple POST request:

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 RVD build the request body from the Name/Value pairs you have defined.

Let’s see it in action:

Request 

POST /services/simplePostRequest.php HTTP/1.1

Content-Length: 21

Content-Type: application/x-www-form-urlencoded

name=foo&lastname=bar

Response

HTTP/1.1 200 OK

Provide POST body manually

You can also provide the POST body manually if you want. For example:

provide POST body manually

 

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.

POSTing json

Using a JSON request body is not much different:

Selection_075

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:

{“name”:“$firstname”,”lastname”:”bar”}

Note that double quotes are being used in the JSON expression. RVD 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.

Using basic HTTP authentication

For services that are protected with basic http authentication the user credentials need also to be provided:
Selection_076

Handling service HTTP errors

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:

  1. create a handler RVD module
  2. bind the ES component to this handler using ‘On Remote Error’ drop down menu

Here is a sample handler module labeled ‘Error announcement’:

Selection_077

 

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:

Selection_078

 



The post Making HTTP requests with External Service client appeared first on Telestax Docs Online.


Viewing all articles
Browse latest Browse all 94

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>