How can I get in my API the slug passed (slug=${params.slug}
,`)
I’m working with vercel AI SDK
const { messages, input, handleInputChange, handleSubmit, isLoading, error } =
useChat({
api: `/api/conversation?slug=${params.slug}`,
});
My API / Not getting the slug:
export async function POST(req: Request) {
try {
const { userId } = auth();
const body = await req.json();
const { messages, slug } = body;
2
Answers
What I tried but not working, I only get the error:
for that call :
You can use req.query for accessing the query string.
Or use req.params by keeping the template of api as
/api/conversation/:slug
and you will get something like
console.log(req.params) // Output: {slug: 'Your Slug'}