Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add formData example for Route Handlers #52358

Merged
merged 6 commits into from Jul 10, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -544,6 +544,29 @@ 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