user4445419
user4445419

Reputation:

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. Example and direction how to do it right will be very helpful! :)

Upvotes: 0

Views: 91

Answers (1)

PPB
PPB

Reputation: 3087

For example

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

req.get('host') will give the hostname like http://example.com.

in req.url you can get url /profile

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

use expressjs for routing http://expressjs.com/ For example

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

Upvotes: 1

Related Questions