I have a question regarding Next 13.4. Since today I can only use Next 13.4. I wonder where the api folder has gone. It is no longer created in this version. It still worked in 13.3. How can I now make a POST or GET request and the result with NextResponse return?
If there isn't any /api folder, you can make one inside /app folder.
In Next 13.4, the api endpoints are treated as route.js, just like page.js.
e.g /app/api/home/route.js
import { NextResponse } from 'next/server';
export async function GET() {
return NextResponse.json({ name: 'Anuj Singh' });
}
so from browser if you navigate to /api/home you will see the result.\
More info on this from official doc : https://nextjs.org/docs/app/building-your-application/routing/router-handlers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With