Next.js Discord

Discord Forum

i can't get a guild id from api

Unanswered
Asian black bear posted this in #help-forum
Open in Discord
Asian black bearOP
import { NextRequest, NextResponse } from 'next/server';

export async function GET(req: NextRequest) {
  // Extract the `id` from the URL
  const { searchParams } = new URL(req.url);
  console.log(searchParams)
  const id = searchParams.get('id');

  // Do something with the `id`
  if (id) {
    return NextResponse.json({ message: `Guild ID: ${id}` });
  }

  return NextResponse.json({ message: 'ID not provided' }, { status: 400 });
}

7 Replies

Asian black bearOP
{"message":"ID not provided"}
Black carp
Search params are GET url parameters like ?id=1234, you want the params object from the NextRequest
@Black carp Search params are GET url parameters like ?id=1234, you want the params object from the NextRequest
Asian black bearOP
so what i need to do if i want like

/1234
Is this impossible?
Black carp
no it's totally possible 🙂
This is what you'd want