Next.js · Middle · Question 32 of 75

How do you return JSON with status 201 from a Route Handler?

Explanation

Route Handlers are built on Web APIs: they take a Request and return a Response (or NextResponse with extra features). res.status().json() is the Express style used by Pages Router API Routes. A plain object isn't a valid response.

Further reading

Problem with a question

Next.js · Middle · question 32

Test yourself

Take the Next.js · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz