Next.js Discord

Discord Forum

simple help about the new app router simple API creation

Answered
Yellowstripe scad posted this in #help-forum
Open in Discord
Yellowstripe scadOP
hello all and thanks in advance,
until now iv worked on nextjs 12 with the "api" folder, now im starting a new nextjs 14 (Typescript) and there is no api folder, i have created one and a file named "my_api.ts" so it will be in route "/api/my_api" , do i need to change it to the folder "my_api" and then create the file "route.ts"?
in addition, can someone plz show me what to write in the file to create a simple api that will give as a response a JSON object?
im a bit lost with the migration - thanks in advance!
Answered by B33fb0n3
you can follow the steps inside the docs on how to create a route handler. After you created a simple route handler with a json response you can migrate your own api routes. Here you can see how you can create a route handler: https://nextjs.org/docs/app/building-your-application/routing/route-handlers
@Yellowstripe scad
View full answer

3 Replies

you can follow the steps inside the docs on how to create a route handler. After you created a simple route handler with a json response you can migrate your own api routes. Here you can see how you can create a route handler: https://nextjs.org/docs/app/building-your-application/routing/route-handlers
@Yellowstripe scad
Answer