Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set http proxy while calling rest endpoint #7

Open
anshul-kumar-agl opened this issue Aug 26, 2020 · 8 comments
Open

How to set http proxy while calling rest endpoint #7

anshul-kumar-agl opened this issue Aug 26, 2020 · 8 comments

Comments

@anshul-kumar-agl
Copy link

Hello, when calling a rest endpoint as below, I need to mention http proxy so that request goes through given proxy. How can we do same?

import { HttpClient, HttpRequest, HttpResponse, HttpMethod, HttpHeader } from "@paperbits/common/http";

response = await this.HttpClient.send(httpRequest);

@azaslonov
Copy link
Member

Hi @anshul-kumar-agl, when you say "mention http proxy", do you mean some kind of header? If possible, please provide more details or analogy of what are you referring to.

@anshul-kumar-agl
Copy link
Author

Hi @anshul-kumar-agl, when you say "mention http proxy", do you mean some kind of header? If possible, please provide more details or analogy of what are you referring to.

Like we mention a proxy url to go every request through in 'request' package as below.

const request = require('request');

const options = {
url: '....',
method:'GET',
proxy:'http://localhost:9000',
headers: {
'Authorization': '....'
}
};

We have to route each request through a http proxy url like above.

@azaslonov
Copy link
Member

Sorry, I'm still confused. Probably you want to have some kind of base URL, so that your request would look like:

const options = {
    url: '/my-relative-url',
    method:'GET',
    proxy:'http://localhost:9000',
};

Is that right?

If not, how would actual HTTP request look like if, let's say, you used something like Postman?

@anshul-kumar-agl
Copy link
Author

anshul-kumar-agl commented Aug 26, 2020

Sorry, I'm still confused. Probably you want to have some kind of base URL, so that your request would look like:

const options = {
    url: '/my-relative-url',
    method:'GET',
    proxy:'http://localhost:9000',
};

Is that right?

If not, how would actual HTTP request look like if, let's say, you used something like Postman?

Url would be complete url. Just that I want request to route through proxy url which internally routes to organisation network. The code I shared using package 'request' works because the url mentioned is reached by routing through http proxy mentioned in proxy property.

Can we set options like above to HttpClient or HttpRequest of your package.

@azaslonov
Copy link
Member

Basically, our client is just a wrapper over XmlHttpRequest, which doesn't seem to have options like proxy (https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest)

This is why I'm asking for an analogy. So, if you did raw HTTP request through Postman or Fiddler how would it look like?

@anshul-kumar-agl
Copy link
Author

Basically, our client is just a wrapper over XmlHttpRequest, which doesn't seem to have options like proxy (https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest)

This is why I'm asking for an analogy. So, if you did raw HTTP request through Postman or Fiddler how would it look like?

The request we do through postman has url and authorisation header. I don't see mentioning anything else. One difference is, since we have application on local machine which sets http proxy on localhost:9000, so application requests, web requests and presumably postman request route through http proxy and hence we get back data.

@azaslonov
Copy link
Member

Right, postman also cannot do that because it uses the same XmlHttpRequest.

So, the only option, I think, is to have a setting that, depending on the environment, would switch between your localhost:9000 and production endpoint.

@joshua-mng
Copy link

joshua-mng commented Dec 5, 2022

@anshul-kumar-agl I think the best way to achieve what you are trying to do is to create a new custom HttpClient based on code from @paperbits-common/http/httpClient, where you can implement proxy like behaviour yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants