Scripting
Send Requests

Send Requests

  • Send requests to any URL using the Thunder Client API
  • Use the tc.runRequest method to execute existing requests
  • Use the axios library to send custom requests

Send Internal Requests

  • Execute existing requests using the API - await tc.runRequest("reqId");
  • This is useful for programmatically chaining requests from the Pre or Post request script.
var result = await tc.runRequest("reqId");
 
// to get the request id dynamically
var result = await tc.runRequest(tc.request.id);
 
console.log(result);

Send Custom Requests

const axios = require('axios');
 
const response = await axios.get("https://www.thunderclient.com/welcome");
console.log(response);
 

Retry Request

  • The tc.retryRequest() function is useful for the retrying the same request.
  • Use the sample code provided in the post request script in Tests tab and modify it according to your needs.
  • The retry request will not execute the pre-reqs and pre-script.
  • Alternatively, you can use tc.runRunRequest() if you would like to run pre-reqs and pre-scripts.
let incrementCount = parseInt(tc.getVar('incrementCount') || "0");
let code = tc.response.status;
 
if(incrementCount <= 3 && code !== 200)
{
    incrementCount = incrementCount + 1
    tc.setVar('incrementCount', incrementCount)
    console.log("retrying request", incrementCount);
 
    await tc.delay(incrementCount * 1000); // exponential delay of 1 secs
    await tc.retryRequest();  // <--- retry request
}
else
{
   tc.setVar('incrementCount', 0);
   console.log("reset incrementCount = 0");
}

Skip Request

  • Skip a request from execution in collection run.
tc.skipRequest('reqId');