# Need API Response in a HTML Format

**URL:** <https://community.postman.com/t/need-api-response-in-a-html-format/35854>\
**Category:** Help Hub\
**Created:** [June 2, 2022, 5:59am UTC](https://community.postman.com/t/need-api-response-in-a-html-format/35854 "2022-06-02T05:59:15Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![imurein](https://avatars.discourse-cdn.com/v4/letter/i/b5a626/32.png) [@imurein](https://community.postman.com/u/imurein)\
**Post date:** [June 2, 2022, 5:59am UTC](https://community.postman.com/t/need-api-response-in-a-html-format/35854/1 "2022-06-02T05:59:15Z")

</div>

Hi,  
I am hitting the url to get a response in HTML Format. But I could not able to get it. I have added the header as Accept - text/html. But still I could not able to visualize in HTML Format. I have attached the image of the response which I got.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/e/c/ecb7d898f6571a3cd7850b20e56b44645660ca77.png)  
Could you please give me some suggestions?  
Thank you.

---

<div class="post-metadata">

**Author:** ![dxlmx](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@dxlmx](https://community.postman.com/u/dxlmx)\
**Post date:** [June 8, 2022, 3:42pm UTC](https://community.postman.com/t/need-api-response-in-a-html-format/35854/2 "2022-06-08T15:42:01Z")

</div>

From personal experience you need to add pm.visualizer to the test tab, you can find the brewery tutorial to guide you through it (recommended) but this is the gist of the code

```auto
let template=`
    <style type="text/css">
        body: {background-color:#e0ffff;}
	h3:{color:#ffff00;}
    </style>

    <body>
    <h2>Beers</h2>
        {{#each response}}
        
            <h5>{{name}}</h5>
            <p>website: {{website_url}}</p>
             <address>{{street}}<br/>{{city}}, {{postal_code}}</address>
                <p>{{country}}</p>

        {{/each}}
    </body>

`;

pm.visualizer.set(template, {response: pm.response.json()});

```

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [June 8, 2022, 4:10pm UTC](https://community.postman.com/t/need-api-response-in-a-html-format/35854/3 "2022-06-08T16:10:33Z")

</div>

Hi @imurein

The ‘Content-Type’ header would need to be in the response headers, not the request headers.  
The request headers are those that you would send with your GET request.  
The response headers are those that are sent back to you from the server.

more info on Content-Type here;

> **[Content-Type - HTTP | MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type)**
>
> The Content-Type representation header is used to indicate the original media type of the resource (prior to any content encoding applied for sending).

It’s also worth noting that the response in your screenshot, generally speaking, doesn’t look like HTML, it looks more like JSON to me.

So if you want to visualise this in HTML format, I think you would have to try out @dxlmx’s suggestion.

Hope that helps?

---

<div class="post-metadata">

**Author:** ![imurein](https://avatars.discourse-cdn.com/v4/letter/i/b5a626/32.png) [@imurein](https://community.postman.com/u/imurein)\
**Post date:** [June 9, 2022, 7:34am UTC](https://community.postman.com/t/need-api-response-in-a-html-format/35854/4 "2022-06-09T07:34:34Z")

</div>

Sorry for the inconvenience and for the delayed response. This post is mistakenly created again.  
Thanks for your @dxlmx response. This code is useful for visualize in HTML format. But I want to get the response itself in HTML format. [I got the reply from @w4dd325 in another post which I have created in the same topic. Content type response cannot be changed by changing the Content type request header]  
and @w4dd325 Thank you for the response. Both replies are useful for me.

---

<div class="post-metadata">

**Author:** ![dxlmx](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@dxlmx](https://community.postman.com/u/dxlmx)\
**Post date:** [June 9, 2022, 1:11pm UTC](https://community.postman.com/t/need-api-response-in-a-html-format/35854/5 "2022-06-09T13:11:21Z")

</div>

You’re quite welcome and hope you get the answer you need. I’m also currently trying to bring the backend response to the frontend. And finding the answer has been difficult. Good luck!

---

<div class="post-metadata">

**Author:** ![dxlmx](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@dxlmx](https://community.postman.com/u/dxlmx)\
**Post date:** [June 9, 2022, 3:33pm UTC](https://community.postman.com/t/need-api-response-in-a-html-format/35854/6 "2022-06-09T15:33:48Z")

</div>

@imurein I just found this series on yt that might be helpful. I’ll be trying this out today  
https://www.youtube.com/embed/videoseries?list=PLyuRouwmQCjmfkOahmQ8MjveL8f2-OyN-&wmode=transparent&rel=0&autohide=1&showinfo=1&enablejsapi=1  
it was very clear. The vid I’m referring to is the 2nd in the series.

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [June 9, 2022, 3:59pm UTC](https://community.postman.com/t/need-api-response-in-a-html-format/35854/7 "2022-06-09T15:59:31Z")

</div>

The second video is mock servers right?  
Is the content coming back from a mock server or an actual API endpoint?

The response still looks like it is written in JSON, so outputting as HTML would probably result in it being displayed in plain text.

Struggling to follow what you are trying to achieve. But happy to try and help if you could dumb it down for me?

👍

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [June 9, 2022, 4:08pm UTC](https://community.postman.com/t/need-api-response-in-a-html-format/35854/8 "2022-06-09T16:08:29Z")

</div>

Would something like this help?  
This shows the JSON in visualizer.

```auto
const jsonData = pm.response.text()

var template = `
<pre>
<code>
${jsonData}
</code>
</pre>
`;

pm.visualizer.set(template);

```

Output;

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/8/a/8a1d915a48781b4a8cc39a6febd35b0f187ed74c.png)

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [June 9, 2022, 4:10pm UTC](https://community.postman.com/t/need-api-response-in-a-html-format/35854/9 "2022-06-09T16:10:45Z")

</div>

or this;

```auto
const jsonData = pm.response.text()

pm.visualizer.set(`
<body>
<P>${jsonData}
</body>
`);

```

Output;

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/3/b/3b42795652fca5c4cb889bd469900d82d1478997.png)

---

<div class="post-metadata">

**Author:** ![dxlmx](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@dxlmx](https://community.postman.com/u/dxlmx)\
**Post date:** [June 9, 2022, 4:27pm UTC](https://community.postman.com/t/need-api-response-in-a-html-format/35854/10 "2022-06-09T16:27:51Z")

</div>

To display in HTML you’d have to create an HTML file and append the data to the HTML element with JavaScript.

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [June 9, 2022, 4:41pm UTC](https://community.postman.com/t/need-api-response-in-a-html-format/35854/11 "2022-06-09T16:41:56Z")

</div>

Hi have this example of putting JSON properties into a table;  
The same approach could be taken but with an HTML template instead of just a table…

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/b/6/b62a4d1dd3fe98e2a2e256bebbaaf2b8ad0ef3a2.png)

code:

```auto
var template = `
    <style type="text/css">
        .tftable {font-size:14px;color:#333333;width:100%;border-width: 1px;border-color: #87ceeb;border-collapse: collapse;}
        .tftable th {font-size:18px;background-color:#87ceeb;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;text-align:left;}
        .tftable tr {background-color:#ffffff;}
        .tftable td {font-size:14px;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;}
        .tftable tr:hover {background-color:#e0ffff;}
    </style>
    
    <table class="tftable" border="1">
        <tr>
            <th>Name</th>
            <th>Email</th>
        </tr>
        
        {{#each response.data.contacts}}
            <tr id=row_{{@key}} onClick="handleClick(this.id)">
                <td id={{@key}}>{{name}}</td>
                <td>{{email}}</td>
            </tr>
        {{/each}}
    </table>
`;

pm.visualizer.set(template, {
    response: pm.response.json()
});

```
