Skip to content

Commit

Permalink
docs: Add formData example for Route Handlers (#52358)
Browse files Browse the repository at this point in the history
Add formData function

---------

Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
  • Loading branch information
3 people committed Jul 10, 2023
1 parent c15d99d commit dfebdb7
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,28 @@ export async function POST(request) {
}
```

### Request Body FormData

You can read the `FormData` using the the `request.formData()` function:

```ts filename="app/items/route.ts" switcher
import { NextResponse } from 'next/server'

export async function POST(request: Request) {
const formData = await request.formData()
return NextResponse.json({ formData })
}
```

```js filename="app/items/route.js" switcher
import { NextResponse } from 'next/server'

export async function POST(request) {
const formData = await request.formData()
return NextResponse.json({ formData })
}
```

### CORS

You can set CORS headers on a `Response` using the standard Web API methods:
Expand Down

0 comments on commit dfebdb7

Please sign in to comment.