简体   繁体   中英

When to use text/plain instead of text/html?

When is it recommended to use text/plain content type over text/html .

Imagine I'm developing an endpoint which is consumed in an async manner (ajax) and only returns a string. Am I supposed to use the text/plain content type in this case?

Is it safe to say that text/html should only be used if the response body contains HTML tags?

With text/plain, you can only send text file content

With text/HTML you can send HTML file content, allowing markup formatting

It's that simple...

Don't overthink it, it's quite self explantory

Text:

<b>some bold text</b>

HTML:

If you want to render the string returned by API in browser as it is then you can use text/plain . Else If you want browser to render you content as html then use text/html .

For Example, if <b>Hi there</b> is returned from API.

So text/plain will print <b>Hi there</b> , but text/html will print .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM