Heads up, I have no experience with any of the front-end stacks, I'm just aware of what's trending (React / Angular / Vue)
So far I have only worked with monolithic MVC applications, but not so long ago I learned how to do REST APIs using Spring Boot
What's the workflow to make use of external REST services in an MVC application?
Let's say I make a basic REST API to handle CRUD
Would the REST calls have to be made in the controller? therefore skipping the model, or do I call them through the view by using ajax? (skipping both the controller and the model)
I'm honestly confused, I just need some guidance
Please and thank you :)
Top comments (8)
Backend:
Frontend:
Example flow with fetch and express in backend:
In this way:
Do you change de database? Only modify the model
Do you change your logic? Only modify the controller
Do you change your routing? Only modify the route
This was a really good explanation! Thank you.
Angular uses http end points in Javascript or Typescript to access the back end. The response being seen in the observable subscription. The content is then bound to the template.
All frontend routing is handled in routetables which call the page. Similar to MVC but there's no controller as the route is all that's needed to bring up the page. Each page calls the backend to inflate the templates.
MVC is a modeling technique used in server (aka back end) software.
So, to be clear, MVC is not something you would implement in react. (edit: Technically you could, but that's not something that would involve a rest api. So not relevant here.)
Your react app would make https calls (often via axios or fetch api) to your server. That server interprets those requests using the MVC you've implemented.
For a more in depth explanation, you should research Node js and its indispensable library, Express. I've learned a lot about those from Academind on YouTube.
A popular point of view, but it's not entirely true, MVC was invented by Trygve as an architecture for desktop applications. (source - folk.uio.no/trygver/2007/MVC_Origi... )
What's now commonly called MVC actually is MVA
To be honest, trying to follow MVC(or MVA) is not something you really need to think about when designing an application.
@jouo
When designing programs, it is important what the components are responsible for, and what they do. Not the technical details of implementation, such as HTTP communication.
If we consider "model" as a domain model, there should not be any external dependencies, except Entity/Value objects that are part of it(like ProductProfile class can be part of Product).
If it's frontend for web application, just don't care about MVC.
I will create a separate API folder in my root directory which will contains its own routes/ and controllers/ folder but the models/, services/ and lib/ folder will be in the root directory shared by both website and API. And then
Import apiRouter from './api/routes/index'
Import genralRouter from 'routes/index'
app.use('/api/', apiRouter)
app.use('/', generalRouter)
It’s not clear to me. Are you looking to do a REST client or server?
Yea for example, if I create a REST server, how do I make use of those REST services in an MVC application?
My goal is to "decouple" the back-end logic from the front-end, so I want to understand how it's done