#How do I get the dynamic route value for an API handler?

4 messages · Page 1 of 1 (latest)

halcyon adder
#

Hello gurus,
I'm attempting to load a "segment" through a fetch request via an API endpoint fetch request in Next.js 13. So far I can get the GET handler to call server side via a client component (yay!). However, I'm struggling to figure out how to get the UUID in the url. I could get that by splitting the url, yet is there a better way?

// src/app/api/segments/[uuid]/route.ts

import { update } from '@/components/data/SegmentJsonConnector';
import { NextRequest, NextResponse } from "next/server";
import { Segment } from '@/components/data/model/Segment';
import { SegmentResponseData } from '../route';

// Get a single segment
export async function GET(req: NextRequest, res: NextResponse<SegmentResponseData>) {
  try {
    // 🤩 I can get here so far! How do I get the UUID from /api/segments/[uuid]?
    console.log(req.url);

  } catch(err) {
    console.log('segments api GET error', err);
    return NextResponse.json(
      { error: 'An API access error occurred. Tell an adult!' },
      { status: 500 }
    );
  }
}
normal mossBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

      🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in <id:customize>

      ✅ You can mark a message as the answer for your post with `Right click -> Apps -> Mark Solution`
      (if you don't see the option, try refreshing Discord with Ctrl + R)
halcyon adder
#

@robust jasper That did the trick. I feel silly for missing it, yet that made life much more wonderful just now. Thank you for your time! 🤩