@@ -217,7 +217,7 @@ The following example sends a JSON response with the status code `200` (`OK`) an
217
217
``` ts filename="pages/api/hello.ts" switcher
218
218
import type { NextApiRequest , NextApiResponse } from ' next'
219
219
220
- export default function handler(req : NextApiRequest , res : NextApiResponse ) {
220
+ export default async function handler(req : NextApiRequest , res : NextApiResponse ) {
221
221
try {
222
222
const result = await someAsyncOperation ()
223
223
res .status (200 ).json ({ result })
@@ -228,7 +228,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
228
228
```
229
229
230
230
``` js filename="pages/api/hello.js" switcher
231
- export default function handler (req , res ) {
231
+ export default async function handler (req , res ) {
232
232
try {
233
233
const result = await someAsyncOperation ()
234
234
res .status (200 ).json ({ result })
@@ -247,7 +247,7 @@ The following example sends a HTTP response with the status code `200` (`OK`) an
247
247
``` ts filename="pages/api/hello.ts" switcher
248
248
import type { NextApiRequest , NextApiResponse } from ' next'
249
249
250
- export default function handler(req : NextApiRequest , res : NextApiResponse ) {
250
+ export default async function handler(req : NextApiRequest , res : NextApiResponse ) {
251
251
try {
252
252
const result = await someAsyncOperation ()
253
253
res .status (200 ).send ({ result })
@@ -258,7 +258,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
258
258
```
259
259
260
260
``` js filename="pages/api/hello.js" switcher
261
- export default function handler (req , res ) {
261
+ export default async function handler (req , res ) {
262
262
try {
263
263
const result = await someAsyncOperation ()
264
264
res .status (200 ).send ({ result })
@@ -277,7 +277,7 @@ The following example redirects the client to the `/` path if the form is succes
277
277
``` ts filename="pages/api/hello.ts" switcher
278
278
import type { NextApiRequest , NextApiResponse } from ' next'
279
279
280
- export default function handler(req : NextApiRequest , res : NextApiResponse ) {
280
+ export default async function handler(req : NextApiRequest , res : NextApiResponse ) {
281
281
const { name, message } = req .body
282
282
283
283
try {
@@ -290,7 +290,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
290
290
```
291
291
292
292
``` js filename="pages/api/hello.js" switcher
293
- export default function handler (req , res ) {
293
+ export default async function handler (req , res ) {
294
294
const { name , message } = req .body
295
295
296
296
try {
0 commit comments