Replacing Parameterized value

I want to replace pe/items/c/prtd-02 in the below snippet with the data i’m getting through a json file and its stored in slugUrl const, please help me how to replace that

response = http.get(
            "https://test.com/pe/items/c/prtd-02?sort=price-asc&q=%3AtopRated",
            {
                headers: {

This is very easy to do through the use of Javascript template literals. Surround your URL with backticks instead of double-quotes, then enclose the variable within ${}.

Here is what that would look like in your example:

response = http.get(
            `https://test.com/${slugUrl}?sort=price-asc&q=%3AtopRated`,
            {
                headers: {

It could also be done with old-school string concatenation, but template literals are far easier to read and interpret.

More info: Template literals (Template strings) - JavaScript | MDN

1 Like

I would also recommend using the http.url wrapper as shown in the last url-grouping

response = http.get(
            http.url`https://test.com/${slugUrl}?sort=price-asc&q=%3AtopRated`,
            {
                headers: {

This will additionally set the name tag (which would otherwise be equal to url) to the original value of the template before replacing it which means you will be able to group those urls together using the name tag. The url one keeps it’s “real” value.