简体   繁体   English

调用REST的Node JS路由功能

[英]Node JS routing functionlity with calling rest

I'm fairly new to node js and I need to develop some kind of reverse proxy in node JS which is getting some URL with path and I need to route the call to rest APi according to the URL (identify the URL by some regex),there is some example or some module which I can use which is open source. 我对节点JS还是相当陌生,我需要在节点JS中开发某种反向代理 ,该代理将获取带有路径的URL,并且需要根据URL将调用路由到其余的APi(通过某些正则表达式识别URL) ,有一些示例或模块可供我使用,它们是开源的。 Example and direction how to do it right will be very helpful! 示例和指导如何正确执行将非常有帮助! :) :)

For example 例如

url = "http://example.com/profile"

req.get('host') will give the hostname like http://example.com . req.get('host')将提供类似于http://example.com的主机名。

in req.url you can get url /profile req.url您可以获得url / profile

  1. https://www.npmjs.com/package/request https://www.npmjs.com/package/request
  2. https://nodejs.org/api/http.html https://nodejs.org/api/http.html

use expressjs for routing http://expressjs.com/ For example 使用expressjs路由http://expressjs.com/例如

app.get('/profile', function (req, res) {
  res.send('GET request to homepage');//or render profile page
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM