Link Search Menu Expand Document

http

work in progress

The action http is used to make http request. This action requires a label that must be a valid http verb.

http <method>{}
// method must be a valid http verb
http post {}
http get {}
...

Supported http verbs are: get, post, put, patch, delete, options and head.

The arguments for the action are:

 TypeRequired?Vars supported? 
descriptionstringnono
whilebooleannoyes
whenbooleannoyes
countnumericnoyes
requestRequestyesyes
responseResponseyesyes

description ( string | optional ) It is used to apply descriptive text to the action.

Example 1: Basic use of argument

http post{
  description = "it creates a new person"
  ...
}

when ( bool | optional ) It is used to control if the action must be executed.

var {
  evalJobStatus = false
}

http get{
  ...
  when = evalJobStatus
}

count ( number || optional ) It determines the number of times the action is executed. Additionally, the variable _.index is increased in each iteration. The value of _.index starts with 0 and it ends with count-1.

Example 1: Basic use of the argument

http list {
  ...
  count = 3
}

while ( boolean | optional ) The action is executed repeatedly as long as the value of this argument is met. Additionally, the variable _.index is increased in each iteration. The value of _.index starts with 0 and increase in 1 in each iteration.

Example 1: Basic use of argument while

http get {
  ...
  while = _.index<=2
}

Request

 TypeRequired?Vars supported? 
baseUrlstringyesyes
pathstringyesyes
quueryParamsQueryParamsnoyes
headersHeadersnoyes
payloadPayloadnoyes
cookies[]Cookienoyes

baseUrl: It contains the base url to the full url

http post {
    ...
    request {
        baseUrl = "http://api.hostname.com"
    }
}

path: It contains the path of the url to be invoked.

http post {
    ...
    request {
        baseUrl = "http://api.hostname.com"
        path = "/v1/users"
    }
}
// POST http://api.hostname.com/v1/users

QueryParams:

They’re represented by a block named queryParams that contains the list of params to be appended to the path.

http get {
    ...
    request {
        baseUrl = "http://api.hostname.com"
        path = "/v1/users"
        queryParams {
            orderBy = ["firstname","age"]
            total = 5
        }
    }
}
// GET http://api.hostname.com/v1/users?prderBy=firstname,age&total=5

Headers They’re represented by a block named headers that contains the list of headers to be sent. The value of each header can be a string or a list of string values.

http get {
    ...
    request {
        baseUrl = "http://api.hostname.com"
        path = "/v1/users"
        headers {
            Authorization = "Bearer ${Token}"
            Content-Type = "application/json"
            Tags = ["service","custom-tag"]
        }
    }
}

Payload It’s represented with a block named payload. This block requires a label whose value must be one of these: json, xml, form or raw. The label means in which format the body will be serialized.

Additional the payload content must be set to an argument named data.

 TypeRequired?Vars supported? 
datastringyesyes
...
set johnDetails {
    value = {
        firstname = "John"
        lastname = "Doe"
        job = {
            company = "wesovilabs"
            role = "developer"
        }
    }
}
...
http post {
    ...
    request {
        baseUrl = "http://api.hostname.com"
        path = "/v1/users"
        payload json {
            data = johnDetails
        }
    }
}

Connection:

 TypeRequired?Vars supported? 
timeoutdurationyesyes
proxystringyesyes
timeout It represents the established timeout for client. Its value must be represented in duration format. (1m1s )
http get {
    ...
    request {
        baseUrl = "http://api.hostname.com"
        path = "/v1/users"
        connection {
            timeout = 15s
        } 
    }
}

proxy It value of proxy used to establish the connection.

http get {
    ...
    request {
        baseUrl = "http://api.hostname.com"
        path = "/v1/users"
        connection {
            proxy = "http://proxy.myhostname.com:9090"
        } 
    }
}

response

This block is used to take data from the http response and put into variables which will be used in the scenario.

There are three special variables that we can use in block response:

  • _.http.body: Returned body from the server.
  • _.http.headers: The response headers.
  • _.http.statusCode: The status code.
http get {
  request {
    baseUrl = ghBase
    path = "/orgs/${orgId}"
    headers {
      Accept = mediaType
    }
  }
  response {
    org = json(_.http.body)
    statusCode = _.http.statusCode
    server = _.http.headers["Server"]
  }
}