0

I want to send an HTTP request with parameters via a query

Example:

  URL: https://api/endpoint?d=1&value=2
WillRasel
  • 3
  • 5
  • Does this answer your question? [How will i pass query parameters to REST API inside a service in an angular application?](https://stackoverflow.com/questions/55934132/how-will-i-pass-query-parameters-to-rest-api-inside-a-service-in-an-angular-appl) – Masood Apr 13 '21 at 16:35
  • Your both parameters are with the same name. Change them to value1 and value2 – Masood Apr 13 '21 at 16:36

2 Answers2

0

To add params for your URL, you need to create the correct options, for example:

const options = { params: new HttpParams().set('value1', '1').set('value2', '2') };
return this.http.get(`${APP_BASE_URL}/endpoint`, options);

Before is an example, you can create a petition with params of many ways.

Check the documentation here

0

You can create an object and pass it as 2nd parameter in get method.

const url="example.com/data";
const parameters = {
  'value1': 1,
  'value2': 2
};
return this.httpClient.get(url, {
  params: parameters
})

This will create your url like below:-

URL: https://api/endpoint?value1=1&value2=2
Vimal Patel
  • 2,785
  • 2
  • 24
  • 38