So, I am trying to migrate from 'old' http to the new httpClient
with the http client I am using this format in my service:
return this.http.get(environment.api+ '.feed.json', requestOptions)
how do I use this in httpClient?
tried many thiungs... including
return this.http.get(environment.api+ '.feed.json', {params: requestOptions.params})
but getting a type missmatch :(
An HttpClient can be used to send requests and retrieve their responses. An HttpClient is created through a builder . The builder can be used to configure per-client state, like: the preferred protocol version ( HTTP/1.1 or HTTP/2 ), whether to follow redirects, a proxy, an authenticator, etc.
Angular RequestOptions instantiates itself using instances of Headers , URLSearchParams and other request options such as url, method, search, body, withCredentials, responseType. These classes are imported from @angular/http API. Finally Http. get() uses instance of RequestOptions to interact with the server.
An HTTP request is made by a client, to a named host, which is located on a server. The aim of the request is to access a resource on the server. To make the request, the client uses components of a URL (Uniform Resource Locator), which includes the information needed to access the resource.
Try this:
const requestOptions = { params: new HttpParams() }; requestOptions.params.set('foo', 'bar'); this.http.get(environment.api+ '.feed.json', requestOptions );
Here is also the link to the docs describing how to do that with examples for headers and URL Parameters: HttpClient
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With