Magento 2 : Can the REST API return plain text?

In your request to the API, you can specify your requested response format using the HTTP header:

Accept: application/xml

Unfortunately the only 2 MIME types Magento supports currently are application/xml and application/json.

The following 2 classes provide the renderer for these formats:

  • Magento\Framework\Webapi\Rest\Response\Renderer\Json
  • Magento\Framework\Webapi\Rest\Response\Renderer\Xml

You can see that both of these classes implement the interface: Magento\Framework\Webapi\Rest\Response\RendererInterface.

You could look into creating your own plain text renderer class and using that to output your response.