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?
4 Answers
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

- 131
- 2
Short answer: There isn't. With 13.4 the Next Team released the app directory as stable. So probably you used this feature while setting up your project. Here a link to the NextJS Blog related to the release.
While reading through the official Docs I stumbled uppon this Information.
In short: That's the equivalent to the API Routes in the pages directory.

- 168
- 5
You can still use API routes with pages/api
directory, they will continue to work without any changes. If you have an ongoing project you don't have to migrate it right now, you can still stick to an old way for a while, for example. If you have used some sort of CLI which does not create this folder, you can do it yourself manually.
However there is a new Next.js v13.4 feature called Route Handlers. It is only available inside the app
directory. It is the equivalent of API Routes meaning you do not need to use API Routes and Route Handlers together. If you are starting a new project you might want to start with Route Handlers right away.

- 15,606
- 2
- 35
- 67
-
1Yes, it works quite differently. I have not tried it yet, but if you have concrete question you can probably post it as a separate question, maybe someone knows! – Danila May 11 '23 at 16:12
Yeah looks like Next just expects us to create route handlers in the designated components themselves where the data is required. So just create route handlers in-component in server components.