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
https://github.com/mikeal/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.