htmlajaxtexthttprequestcontent-type

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?


Solution

  • 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:

    some bold text