Search code examples
react-nativeapiweb-applicationsnext.jsmobile-application

Can I use NextJs API routes to handle both web and mobile app?


I want to create web app in Nextjs and in the future mobile app in React Native. But I am confused what api to use. Do you think that the Nextjs api can handle both web and mobile apps? Is this possible and is it good idea at all? Should I use PHP backend for that? Thank you very much.


Solution

  • With the assumption that you are talking about API Routes :

    I would ask you that you think through the scale of your web and app. If this is a simple web/app that you do not expect to grow much - The NextJS API which is similar to standing up an nodejs express server is not a bad option.

    Remember a few considerations when designing this API

    1. You may have to distinguish the request origin (web/app)
    2. CORS may have to be customized - Next exposes this
    3. You could set an app specific route to ensure isolation or use headers to distinguish behavior if your application bifurcates in the future.

    These concerns are shared even if you made a PHP, ExpresJS or any other API middleware.

    Once you are past all this, i would ask you to consider

    1. Using a GraphQL server like Apollo that works nicely with Next and is custom built for this purpose..
    2. Evaluating API Gateways for security and scale.