0
HTML我有方法的API上的GET返回職位的JSON格式列表渲染來自REST API的NodeJS,快速和EJS
那麼我這條路線mysite.com mysite.com/api/posts/posts應該用EJS JSON從/ api/posts中提取
如何用NodeJS Express實現這一點? 老年人NodeJS開發人員如何處理這個問題? 你能幫我通過拋出一些代碼或者一個NodeJS開發者在GitHub中做了些什麼嗎?
我的代碼如下所示:
routes.js
(...)
// GET route find all posts
app.get('/posts', postsController.findAll);
(...)
postController.js
(...)
findAll(req, res, next) {
// This is the part that I am not sure, populate
// data with the API results
let data = app.get('/api/posts', apiPostsControllers.findAll)
res.render('index', {
page_layout: 'posts',
page_title: 'Posts,'
data: data
});
}
(...)
非常感謝
谷歌是你的朋友!這應該是一個很好的起點:https://scotch.io/tutorials/use-ejs-to-template-your-node-application –
@PaoloMangia我認爲你沒有讀到我說的話,對不起隊友,但我知道如何使用谷歌和像那樣的結果是毫秒,你給我發送的鏈接,他們立即渲染視圖,但我想完成的是讓API和API給我JSON結果,然後渲染它,什麼我想我必須有兩條獨立的路線,但我不知道哪一條是最好的方法。 :( – Matt