Giter VIP home page Giter VIP logo

Comments (5)

batuhan avatar batuhan commented on May 25, 2024 2

Hey @mimiz,

I believe frontend (react bits) and the backend (api) should be decoupled. React is the hot thing today but tomorrow we can all move onto the next hot thing in the market. API's are supposed to be independent of that.

Decoupling also allows you to use another language/framework in the future with your API too, if you so choose.

You have a few options for code sharing though:

  • Build a package (NPM): You can put all of the common utility code inside an NPM library. Keep in mind you can "install" libraries outside of NPM, via Git, HTTP or from local directories. This also allows you version your code, but that's a double edged sword since you would, in theory, need to keep pushing new versions for most of your edits.

  • Import it directly: You can create a directory structure with 3 main directories: frontend, api and common. In your API or frontend code, call it with require('../common') or the equivalent import ES6 syntax. If you use bundling (for example with webpack), this also bundles the common functions inside each application's (api and frontend) own bundle.

Let me know if you have more questions.

Should also point out I'm no longer part of @barbar, so opinions of them may be different from my own.

from vortigern.

batuhan avatar batuhan commented on May 25, 2024 2

You can always proxy the API inside the frontend code, which easily allows you to serve both on the same domain and from the same application. Of course, this all depends on your specific needs.

from vortigern.

ufukomer avatar ufukomer commented on May 25, 2024 1

https://twitter.com/Todd_McLeod/status/920784947215863808

from vortigern.

mimiz avatar mimiz commented on May 25, 2024

Hey, @batuhan,

Thanks a lot for your advice, and I think you are right. Sorry for my late response but I was on holiday AFK!
I will follow your ideas !

Regards
Rémi

from vortigern.

bherila avatar bherila commented on May 25, 2024

@batuhan what I do is implement my API separately, export a swagger definition file, and then generate a typescript proxy interface which I put in a NPM package. Then I import this API proxy in my react-native code as well as the vortigern-based site.

I actually implemented the API in C# using ASP.NET Web API which worked really well for my backend needs. All the types are initially defined in C# and Typescript versions of the classes are generated through the swagger toolchain.

Resources:

  1. Swagger: https://swagger.io/
  2. Swagger-codegen: https://github.com/swagger-api/swagger-codegen

from vortigern.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.