#app router outputting plain text

1 messages · Page 1 of 1 (latest)

onyx ember
#

Can I render a non HTML document, for example a plain text using the app router?

wheat zincBOT
#

Hi @onyx ember. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Yes. In the App Router, create a Route Handler and return a Response with a text content type.

Example (app/hello.txt/route.ts):

export async function GET() {
  return new Response('Hello, plain text!', {
    headers: { 'Content-Type': 'text/plain; charset=utf-8' },
  })
}

Route Handlers support non-UI responses like JSON, XML, files, and plain text, and you can define custom endpoints such as rss.xml or other file-like routes (e.g., llms.txt) by placing a route.ts under a matching segment (e.g., app/rss.xml/route.ts) and setting the appropriate content type ( Non-UI Responses, Content types ).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: