rpeshkov
rpeshkov

Reputation: 5047

Nancy proxy requests

Is it possible to proxy requests on specific address in Nancy?

For example, when someone make a request on http://localhost:1234/need-to-proxy, Nancy should send request to http://another-server:9000/api and return response from this server.

Upvotes: 2

Views: 1357

Answers (2)

derek
derek

Reputation: 123

Get["/"] = parameters =>
    {
        return this.Response.AsRedirect("http://google.com");
    };

Upvotes: 0

Sunny Milenov
Sunny Milenov

Reputation: 22310

Do you need to forward all the request data - query string, post data, headers, etc? Its absolutely possible, the question is "why". There's plenty of reverse proxy software out there, which most probably will behave better than whatever you need to write.

If you need to inspect the incoming request, and build a different one for the internal service, then it makes sense to write your own code.

You can create an async route for your incoming request, do async call to the internal service, massage the response (if needed) and return. Calling another server is no different than any other work you would normally do in your route.

Upvotes: 1

Related Questions