Skip to content

Commit

Permalink
improve the code example for a more realistic scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
joulev authored Sep 24, 2023
1 parent 78413f0 commit 1cbb813
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,23 +388,23 @@ export async function GET(request, { params }) {

### URL Query Parameters

The request object passed to the Route Handler is a `NextRequest` instance, which has [some additional convenience methods](/docs/app/api-reference/functions/next-request#nexturl), including more easily handling query parameters.
The request object passed to the Route Handler is a `NextRequest` instance, which has [some additional convenience methods](/docs/app/api-reference/functions/next-request#nexturl), including for more easily handling query parameters.

```ts filename="app/test/route.ts" switcher
```ts filename="app/api/search/route.ts" switcher
import { type NextRequest } from 'next/server'

export function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams
const name = searchParams.get('name')
return new Response(name ? `Hello ${name}!` : '`name` is not provided.')
const query = searchParams.get('query')
// query is "hello" for /api/search?query=hello
}
```

```js filename="app/test/route.js" switcher
```js filename="app/api/search/route.js" switcher
export function GET(request) {
const searchParams = request.nextUrl.searchParams
const name = searchParams.get('name')
return new Response(name ? `Hello ${name}!` : '`name` is not provided.')
const query = searchParams.get('query')
// query is "hello" for /api/search?query=hello
}
```

Expand Down

0 comments on commit 1cbb813

Please sign in to comment.