How to print only the hostname from a request url

Hey, I have a use case where i need to store the host URL as variable,
I used few scripts

  1. pm.request.url.host >> this gives output in array format like
    `[“app”, “xyz”, “com”]

  2. 0: “app”

  3. 1: “xyz”

  4. 2: “com”`

Can someone help me to print it like app.xyz.com

@dannydainton need your help here

Thanks in advance

Hi @swasthik, you can do it using join() method :blush:

Please try the below snippet.

console.log("URL is : " + pm.request.url.host.join('.'));

Please let me know if this is your expectation :slightly_smiling_face:

2 Likes

yes, perfect Thanks @bpricilla :slight_smile:

1 Like

@swasthik Great to know!! Just sharing this link for you to know more about this join method :slightly_smiling_face:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join

You can also use this without using an additional .join() method. :smiley:

console.log(pm.request.url.getHost());

There are a bunch of helper methods available in the auto-suggestion list.

1 Like