I try to understand the API first architecture to apply on web application, and found out some info here, Advantages of a separate REST backend API?
Below I attach an example for better answer of the questions. I start using Angular.js for front-end. Node.js, Express.js for server.
folder structure
|-- server.js
|-- app
|-- models
|-- views
|-- index.html
|-- about.html
|-- contact.html
|-- controllers
|-- app.js
|-- node-modules
app folder is a MVC structure for angular app. All of the POST GET PUT DELETE, MongoDB, Redis connection are in server.js. But when the server file get bigger, what is the best way to organize those business logic?
There is no view engine set on server.js. If I create "routes" folder in express, is this actual carry out an API first concept? Let's say, when user clicks a button to submit a form from browser directly, in this case, is server responsible for presentation layer?
index.html
<form method='POST' action='/register'>
// some code here..
<button type='submit'>submit</button></form>
server.js
var rootPath = './app/views'
router.post('/register' (req, res) =>{
// some code here...
res.sendFile( rootPath + 'index.html');
});
Thanks in advance.