Parameterize URL

Hi Team,

How to parameterize the request URL.

let resp= http.get('${ransrch.p_Search}', searchHeader);

While running the test it getting failed. I can see the correct value on the console log, but the request getting failed.

 console.log('Search value : ',ransrch.p_Search);



Hi @Gerard.

I’ve created a custom function for such purpose - maybe you can get some use of it.

import {URLSearchParams} from '';

export function securedGetWithParams(url, params, payload) {

    let searchParams = new URLSearchParams();

    for (const [key, value] of Object.entries(params)) {
        searchParams.append(key, value);

    return http.get(`${url}?${searchParams.toString()}`, payload);

In case you need more info navigate to this link.

1 Like

Hi , your approach works well. But I achieved it by simply constructing the URL and using it.

let searchValue=ransrch.p_Search;
let url='You searched for ' searchValue -;
let searchRes = http.get(url, searchHeader);

@Gerard you are using string in your origianl example while you seem to want to use templates literals. To do that you need to use a `(backtick) instead of '(single quote).

1 Like