Search code examples
restfrontendweb-development-server

Do I use stacks or do I make isolated APIs and Frontends?


I have been making Web apps for a while now. Mostly frontends.

I have always wanted to make fully functioning web sites, and therefore, my question.

The question might be dumb, so please bear with me...

I have realized that there are two ways I can develop web apps:

  1. I initialize/work with stacks (MERN, LAMP). Everything inside one folder. The backend throws the HTML code (as far as I understand).

-----or-----

  1. I make a Frontend service (localhost:3000 for React (for example)) and I create a RESTful API (with its own endpoint, say localhost/somethingBackend or something like localhost:8000).

My question is:

Did I understand this right? Is this how webdev works?

And the more important one, WHEN TO USE WHAT? What is faster or better?

Normally I'd Google something like this, but there's either not much information about this, or more probable, I'm searching the wrong thing.

Please help me clear my concepts.


Solution

  • Both are correct approaches. But the first one is a more traditional approach towards web app but it comes with the difficulty of writing sensible, reusable code in it compared to writing random-looking nonsense which happens to work, along with performance and reliability issues.

    Writing code with a RESTful approach is what I personally prefer. The majority of frameworks use this approach. Maintaining code between teams is easy.

    Modern backends like nodejs can also throw HTML as a response(see templating engines) but as I said option 2 is always preferred.