Use Express JS .all() method: detect which VERB was actually used

I'm going to create an /api endpoint blindly proxying requests and responses back and forth to the legacy RESTful API system (written in Ruby and hosted on a different domain).

This an intermediary transitional step, so that should just work.

So, I see how that can be easily achieved with app.all(). But as the API is RESTful I do also have to maintain the HTTP verb used for the request - so, can I detect it from the req object? If not, of course I can subscribe 5 handlers for GET, PUT, POST, DELETE, OPTIONS, but it will be much better to avoid this.

Also, how should I deal with the request body (query string and payload)? I assume I'll need to manually recreate the query string from the parsed req.query and pass req.body to request as is - is it right?


I guess you all need is req.method. And to deal with body, add express.bodyParser() middleware.

If you just want to pass requests and return the response then you are looking for a proxy.

I'd recommend checking out node-http-proxy. Just load the proxy library, init a proxy, and proxy all requests.

Need Your Help

Chrome can't load web worker

javascript google-chrome web-worker

I am working on a project that uses a web worker.