skip to Main Content

I have seen Next JS API feature, it provides you the API folder where you can create API for frontend. But I am still confuse about few things.

  1. Does it replace the need of backend e.g database and file handling etc
  2. Is this for just sending you the response in JSON e.g mock service.

I am unable to understand the actual use case of this. I want to create full stack website. Frontend, backend, database, etc. Would this be possible with just Next JS?

Thank you.

I have tried some examples for returning the JSON

2

Answers


  1. You can absolutely use API routes as a replacement for a real backend with a server, if you want. They’re serverless, located in one repo, and so much easier to manage. As for use cases, you can use API routes to process webhooks (for payments with Stripe, for example), fetch data from a database or external API, and the popular auth library NextAuth/Auth.js even uses API routes for its implementation. For a fullstack code example, check out the Next.js Commerce starter kit, which uses API routes.

    Login or Signup to reply.
  2. Much recommend use BFF pattern with Next.js /api folder

    BFF – Backend for Frontend Design Pattern with Next.js – DEV Community

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search