Plain text - API response
Answered
Havana posted this in #help-forum
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.
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.
4 Replies
@Havana 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.
return new Response("this is served in plain text")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.
Thanks very much!
.json() Thanks very much!