节点 JS -URL 参数像 example.com/profile/me 一样简化

Node JS -URL Parameters simplified like example.com/profile/me

本文关键字:一样 me profile -URL JS 参数 com example 节点      更新时间:2023-09-26

如何将类似于"www.example.com/movies?year=2009&genre=action"的网址缩短为"www.example.com/movies/2009/action"?

使用节点js,我开发了API,它带有get请求返回JSON数组。但是我需要呈现页面。如果我在我的API中使用res.render(page(,那么我可以将json发送到我的移动应用程序。那么我该如何实现这一目标呢?说,facebook.com/mark- 检索马克的个人资料 facebook.com/john - 检索约翰的个人资料

任何帮助,不胜感激。

提前谢谢。

可能想要使用 express。 从 Scotch.io 教程和文档中:

app.get('/movies/:year/:genre', function(req, res) {
    // How you retrieve moviesJSON depends on your database
    var moviesJSON = findMoviesByGenre(req.params.genre); 
    res.render('MyView', moviesJSON);
});