Do you know how to use Angular libraries that use HttpRequest instead of CapacitorHttpPlugin

I would like to reuse some of my Angular that use Http requests instead of CapacitorHttp. I don’t now how to manage that.

Should I create an HttpInterceptor to transform my HttpRequest into CapacitorHttpPlugin (requests) ? If so how whould you do that ?

Do you think of an other solution ?

Maybe I misunderstood how to use CapacitorHttp ?

Thanks

If you enable CapacitorHttp Plugin, it overwrites XHR/fetch to use native connections instead of the WebView connections.

You don’t have to do anything with your angular http requests, if you enable the plugin they will use native connections as it uses XHR or fetch under the hood.

If you don’t want to enable the plugin, so it doesn’t overwrite XHR/fetch, then you can call the plugin like Capacitor.Plugins.CapacitorHttp.request(...) only for the connections where you want to use native code.

Sorry but after several tests obviously my problem does not come from there. I don’t see any difference between the Http and CapacitorHttp requests apart from adding a header “Access-Control-Allow-Headers: Content-Type” so I deduce that the plugin is activated.

My problem comes from the fact that my requests are built by my Angular library and use the base href of the application. I would like to set a particular base href when requests are intercepted by CapacitorHttp to prevent such requests:

On electron : capacitor-electron://-/api
On android : http://localhost/api

Do you know how to manage that ?

I have make an HttpInterceptor to rewrite the url before CapacitorHttp Plugin catch and transform the HttpRequest into CapacitorHttpPlugin (requests).