Next.js Discord

Discord Forum

NextResponse: send empty body with status 204

Answered
Wookie posted this in #help-forum
Open in Discord
I basically wanna send an empty response with status code 204, what would be the way to do this using the app directory and route handlers?
Answered by Wookie
return new NextResponse(undefined, { status: 204 })

This does seem to work somewhat but don't know if it's the right way to do it
View full answer

11 Replies

return new NextResponse(undefined, { status: 204 })

This does seem to work somewhat but don't know if it's the right way to do it
Answer
@ᴉuɐpɹɐɐ It should be `NextResponse`
oh yea sorry that is it my bad, ok well then it is the right way to do it it seems
typo woops
well can consider this closed basically but would be open to any other opinions
might not even need this anymore with the new react server components thing
@Wookie I basically wanna send an empty response with status code 204, what would be the way to do this using the app directory and route handlers?
i would use return new Response(null, { status: 204 }), but yeah these options are good
since you don't care about the response body, can put anything in there
Asian black bear
I suggest against undefined since it's not valid JSON
So send null instead.
ok thanks a lot guys