I just coded sample files.
my ejs file display some data after receiving the data from API call.
my code is shown as below and the pattern of my code follows
node(router) --> call api(axios) --> display data on the ejs file.
//index.js
...
...
router.get('/dashboard', function(req,res,next){
try {
let result = await axios({ //Call API
method: 'get',
url: 'http://localhost:3001/user',
data: {
id: '1129',
lastName: 'Test'
}
});
res.render('dashboard', {data: result.data}); //display the received data
} catch (error) {
next(error)
}
})
module.exports = router;
//dashboard.ejs
...
...
<div>
<p>js data : <%=data%></p> //displays the data I jsut received from Axios
</div>
...
...
But what if some client types input value and I want to execute API call(post or put) with the client input value?
likes.. get client value from ejs --> send the value to node(router) --> call api(axios)
is there any way to do that?(without ajax, because I am trying not to use ajax).