HTTP Request

Watch this video to learn how to use the HTTP Request building block.

What you learn in this lesson

  • How to use HTTP Request as part of your cases.
  • How to send an e-mail from a flow.
  • How to call a REST based API use the result in the flow.
  • How to format the result from a HTTP Request.
  • How to use a persistent variable.

Lesson Overview

Watch this video to learn how to use the HTTP Request building block.

What you learn in this lesson

  • How to use HTTP Request as part of your cases.
  • How to send an e-mail from a flow.
  • How to call a REST based API use the result in the flow.
  • How to format the result from a HTTP Request.
  • How to use a persistent variable.

In this video I will look at the HTTP Request building block and give some examples of how to use it.

A lot of applications are based on HTTP/REST based APIs so this building block can be used in various scenarios.

I’ll give an example of how to use the HTTP block to do a simple kind of monitoring and also show an example of how to call a service to get a customer id returned.

I’ll start with the Monitoring example, where I’m checking if https://leaptest2.staging.wpengine.com is running as expected every 3 seconds. If not, I’ll send a mail to my internal IT department and notify them about the problems.

I’ll start by adding a HTTP Request block.

  • Add HTTP Request
  • Expand building block

When the building block is executed, it will perform a HTTP request to the URL specified. It’s possible to add custom headers to the request. I won’t use it for this demo, but it can be necessary to add headers for some solutions, for instance when you are using certain single-sing-on solutions, you need to add tokens into an Authorization header.

I’ll just add “https://leaptest2.staging.wpengine.com” as the Url – not in the field, but in a Set Text block, so it’s easier to reuse the content.

  • Add Set Text
  • Set text value to “https://leaptest2.staging.wpengine.com”

If I have to do a POST to a system you can specify the BODY and of course use fields to add content from other building blocks when you compose the data to post.

I’m just gonna use a GET method here.

  • Set method to “GET”

The next thing to do is to check the result coming back from the request. In the Response section I have 4 different properties:
– Response code, which I’m gonna use in a while
– The Headers and Body and finally the Response time.

In this case I’ll check if the response code is 200 OK, by adding a Compare block.

  • Add Compare

I’m setting “Value B” to 200, so if the response code is 200, the Compare block will return true and trigger the output connector at the top.

  • Add 200

I’ll add a Wait block if the response code is 200 to make sure we only ask every 3rd second.

  • Add Wait

Then I’ll wire up the wait block with the HTTP Request to make a loop.

  • Add loop connector from Wait to HTTP Request

So now we check the web site every 3 seconds or until the response code is different from 200.

In case it’s not 200 I want to send a mail, so I’m gonna add a Send E-mail block to the Compare block. I have set up the base e-mail setting in the Settings area in advance. Normally you should be able to get this info from your operation people.

So in case the response code is different from 200, the “incorrect” output connector is triggered.

  • Add Send Email

I’ll just add a test email address.

The subject is: “web site not responding”, and the body will then use the Set Text and specify what web site is not responding.

  • Add values to fields

I’m just gonna lower the timeout to better illustrate what will happen if the web site is not responding.

Let’s run the case.

  • Run case

As we can see, the case is just running, luckily verifying that the web site is responsive.

In order to trigger the “not OK” state I’ll just add a non-existing domain and run the case again.

  • Change Set Text text value to “https://leaptest2.com”
  • Run case.

As we can see in the log, a mail is now sent to my test address because the response code was 404.
So this is an example of how you could use the HTTP Request in a workflow.

The other example is calling a method in a local REST API and get a customer ID returned.

The HTTP Request will then serve 2 purposes:
– Ensure that the application is running – or at least that the API is running.
– Get an ID that can be used in one or more test cases.

I’m just gonna clean up the canvas.

  • Clean up canvas

In the Set Text I’ll add the URL to the end point.

  • Paste value to Set Text

The API is based on the WebAPI template in ASP.NET and is running on my local machine. The end point is hardcoded to return a string representing a customer ID.

When the customer ID is returned, it is returned as a string including quotes, so I need to format the result before I store the value in a variable for later use. I’ll add a Change Text block and hook it up with the response body.

  • Add Change Text
  • Wire up Response Body to Change Text
  • Remove quotes – replace quote with empty string.

To remove the quotes, I’ll replace the quote with an empty string. Then I’ll add the value to a new variable, “CustomerID”, and specify that the variable and its value should be available to all test cases in this run.

Let’s run the case.

  • Run case

So, the HTTP Request received the customerID, the Change Text removed the quotes and then the
variable was set. Now this variable can be used in other test cases or later in the current workflow.

This ends the look into the HTTP Request building block, giving 2 examples of how to use the building block.

This ends this video.