Next.js Discord

Discord Forum

Plain text - API response

Answered
Havana posted this in #help-forum
Open in Discord
HavanaOP
Hello, I'm using Next 13.4.12 (app router)

I'm just wondering if it's possible to serve an API route and have a plain text response instead of JSON?

I've got a 3rd party hitting a specific endpoint and they require a plain text response and there's no scope for that to change.
Answered by joulev
return new Response("this is served in plain text")
View full answer

4 Replies

Answer
@joulev `return new Response("this is served in plain text")`
HavanaOP
So you don't have to return NextResponse ?
no, you can simply return a Response. NextResponse is just an extension of Response. if you want NextResponse:
return new NextResponse("balh blah")
HavanaOP
I assumed it had to be NextResponse with one of the methods e.g. .json()
Thanks very much!