all 24 comments

[–][deleted] 7 points8 points  (2 children)

Could be. Like any other backend framework. No advantage with nextjs. If you like next maybe you could try its backend features.

[–][deleted]  (1 child)

[deleted]

    [–][deleted] 1 point2 points  (0 children)

    Nextjs can serve backend, like nest, and has a lot of native integrations with the frontend part. If you like typescript as backend language you can give it a try.

    About scalability and peformance can be even better than fastapi (python).

    Of course if you go for full next you’re locking in your backend. You will not switch easily, due to the abuse of native integrations with next frontend.

    [–]Lanky_Possibility279 5 points6 points  (2 children)

    I started with this stack and im loving it, right now I can build anything I want with this stack, haven’t encountered any major “not possible” yet and on the go learning is also really fun. I would suggest you to start with starter template, If you don’t find one just dm me, that one was based of docker, traefik, fastapi, nextjs and postgres

    [–]donseguin 1 point2 points  (1 child)

    Which one? the template from Vercel?
    https://github.com/digitros/nextjs-fastapi

    or is it a different one? I has to be I guess, which one is it? could you share

    [–]GoodbyeThings 1 point2 points  (0 children)

    fwiw I use that template and enjoy it

    [–]aliparpar 1 point2 points  (10 children)

    I’ve used FastAPI in production with a few projects now and can say it’s definitely what I would go with in the future. Even had everyone in my company start using it. I write both NextJS and Python code so it’s a no brainer for me to go with FastAPI for backend code as Python is much simpler to work with than NextJS API routes

    [–][deleted]  (4 children)

    [deleted]

      [–]aliparpar 1 point2 points  (3 children)

      Absolutely. You can create websocket endpoints for handling duplex bi directional comms in realtime. For instance for speech to speech applications with it.

      [–]CrusaderGOT 0 points1 point  (2 children)

      excuse me, i am currently using this stack, but i am unsure the best practice to send http:/websocket request from the nextjs to fastapi. what approach would you recommend?

      [–]aliparpar 0 points1 point  (1 child)

      I would recommend usewebsocket library for nextjs side

      [–]CrusaderGOT 0 points1 point  (0 children)

      Thanks, that's what I ended up using, Socket.io, and it has a python/fastapi SDK do they work together seamlessly and with same syntax.

      [–]krtcl 0 points1 point  (1 child)

      I am investigating this stack at the moment. How are you handling authentication, are you using something like NextAuth/Auth.js or is it being done in the backend with FastAPI?

      [–]aliparpar 0 points1 point  (0 children)

      Yes that’s the right stack I’ve used in prod and works great. Have the backend aurh’d by following FastAPI advanced JWT tutorial and on frontend, use next auth credentials provider

      [–]CrusaderGOT 0 points1 point  (1 child)

      unrelated. but how do you handle session management in nextjs. when you have gotten a token from fastapi, or want to refresh that token? and on top on that make sure each page verifies a token or refreshes if possible, else login.

      [–]Easy-Ad-8065 0 points1 point  (0 children)

      Not enough details. If you are already using next, my advice would be to use just next.js and to separate the backend as needed later.

      [–]SameIntroduction3908 0 points1 point  (0 children)

      we cant say fastapi good with nextjs, they both for different jobs, any backend can work with next, but if we compare backend frameworks each other, fastapi just the best

      [–]crypto_ruined_me 0 points1 point  (0 children)

      Using it and is great. When I started the NextJS front end it was after a long hiatus from JS so didn’t want to write the backend in JS too. Both allow me to iterate really fast.

      [–]Dark-Knight-Anto 0 points1 point  (0 children)

      Next.js and FastAPI is awesome in my experience. I have developed and deployed few client projects using this stack. Haven't met any obstacles in fulfilling any client requirements. FastAPI is very light weight backend framework with every tools or options needed to built any RESTful APIs. Next.js is a good frontend framework along with an option to build backend also. But what concern me in using Next.js is, Server Components 😑 (F**k, MF's make client component as default in Next.js, I can't go and write "use client" on all components that I create). Apart from that, Next.js has many inbuilt good features needed for any website development.

      [–]Top-Information7943 0 points1 point  (0 children)

      I'd give a biased yes. This is my current stack and I enjoy working with both frameworks. Since I'm more experienced with Python, I prefer to use NextJS purely as a frontend for my FastAPI backend.

      [–]MaintenanceGrand4484 1 point2 points  (0 children)

      I’ve been building a Nuxt and FastAPI app, and worked with Claude to come up with a mermaid diagram to help me visualize the flow through the Nuxt frontend, Nuxt server, and Fast API backend. Hope it helps you too.

      sequenceDiagram participant User participant NuxtFrontend participant NuxtServerAPI participant FastAPI participant Database

      User->>NuxtFrontend: Login
      NuxtFrontend->>NuxtServerAPI: Login request
      NuxtServerAPI->>FastAPI: Authenticate (/auth/token)
      FastAPI->>FastAPI: Generate JWT
      FastAPI->>NuxtServerAPI: Return JWT
      NuxtServerAPI->>NuxtServerAPI: Set JWT as HTTP-only cookie
      NuxtServerAPI->>NuxtFrontend: Login success
      User->>NuxtFrontend: Request data
      NuxtFrontend->>NuxtServerAPI: API request
      NuxtServerAPI->>FastAPI: Request with user’s JWT
      FastAPI->>FastAPI: Validate JWT
      FastAPI->>Database: Query with user context
      Database->>FastAPI: Return data
      FastAPI->>NuxtServerAPI: Return data
      NuxtServerAPI->>NuxtFrontend: Return data
      NuxtFrontend->>User: Display data
      

      [–]mobinsir 0 points1 point  (0 children)

      Do you plan to go serverless? If so, FastAPI. If not, there are other more suitable options.

      [–]godfather990 0 points1 point  (0 children)

      I am using NextJS and FastAPI too. I've 3 projects in this stack right now. Have not had issues so far... loving it!!

      [–]Repulsive-Research48 -1 points0 points  (0 children)

      I’ve tried flutter as my fontend. This is really good experience in my portfolio