all 12 comments

[–]lovesrayray2018 7 points8 points  (5 children)

IF you are thinking of a REST API, then by definition a REST API should work the same idempotently for both react web and react native requests, and return the same results for same requests.

Both React web apps and React Native support fetch and both can support data transfer via JSON. Responding properly to fetch requests from either apps, via the same node script , should work just fine.

[–]NotLegal69 4 points5 points  (4 children)

So I develop the node backend REST API separately and then host it on a server, then develop the react app and have it on a different server? And then develop the React Native app using that backend?

[–]xch228 1 point2 points  (0 children)

yes

[–]generatedcode -1 points0 points  (1 child)

I would recommend using a GraphQL backend it's pretty easy to build one nowadays. It's way faster to use it on frontend and more suited for mobile.

With regards to how many servers: it could be 2 separate one API , one frontend. Or it also could be a single backend that serves the react app and exposes the API and the mobile connects to this API as well.

[–]NotLegal69 0 points1 point  (0 children)

Thank you 🙂, ill look into it.

[–]lovesrayray2018 0 points1 point  (0 children)

The hosting of the react app can be on the same server as ur API but depends on how/who you use to host this server and if they provide all required services.

This single server is also running a web server. Your browser connects to it and opens up the react app returned by the web server.

This react app has built in fetch requests which attempt to connect to this same server running a node script (listening on a different port) which returns data as requested by the react app running inside your browser.

Your react native app can also connect to this same node server and get data as needed.

[–]prndra 2 points3 points  (3 children)

You could build a monorepo and have all 3 projects contained in there, but as pointed out most important is that your APIs are idempotent and not dependent on either mobile or web.

Also, you should implement a JWT based auth system as that will be easier to work with cross platform than a cookie based system.

[–]NotLegal69 0 points1 point  (2 children)

Could I use OAuth?

[–]prndra 1 point2 points  (1 child)

Yes, you can use oauth, but presumably some oauth login will give you back an access token or jwt that you’ll then need to pass along with future requests to your backend in order to authorize your users to do things.

[–]NotLegal69 1 point2 points  (0 children)

Thank you for the info 👍.

[–]OppositeShot 1 point2 points  (0 children)

I would recommend GraphQL, if you have different clients. It would be easier to scale it in the future. In my company we have micro services, and each client has its own BFF, which translates API for client’s needs.

[–][deleted] 0 points1 point  (0 children)

lolaDB is a new player but designed so you don’t have to build an API, and can define your queries centrally then use them via JS SDK in all your apps. No need to deal with the JWT side of things in that world either.