How to have same backend for Flutter mobile app as of nodeJS website?

173

Just created different route for website and flutter application.

Route for website :

router.get("/api/web", (req, res) => {
    res.render("home", someData)
})

Route for mob-application :

router.get("/api/app", (req, res) => {
    //send response
})
Share:
173
kallis
Author by

kallis

Updated on December 27, 2022

Comments

  • kallis
    kallis over 1 year

    I already have a website with nodeJS and EJS templating engine. I know I should configure my server to return data in JSON format in order to have a backend for the flutter app.

    I don't have much computer background and I'm a bit confused.

    Here is what I'm doing in my website codes.

     router.get("/", (req, res) => {
     res.render("home", someData)
    })
    
    • Kidas
      Kidas about 3 years
      you can create a new route like /api/ where you will serve json, or do you intend to sharee the same route between you webapp and flutter ?
    • kallis
      kallis about 3 years
      I was thinking of the same route.
    • kallis
      kallis about 3 years
      But if that's the only way, then I'll create a new route.
    • Kidas
      Kidas about 3 years
      else you can return json, and use Flutter for your webapp and mobile, like that you will share the same code https://www.filledstacks.com/post/create-and-deploy-a-flutte‌​r-web-app/
    • Wali Seddiqi
      Wali Seddiqi over 2 years
      you can use Dio or Http packages in Flutter in order to send request to your backend API.