-2

I have a strange problem I cannot understand. Here is the code calling REST endpoint:

this.http.get<AllApplicationType[]>(environment.SUDS_API_SERVICE_URL + environment.SUDS_ALL_APPLICATIONS_URL, this.setQueryParams(page, size)).toPromise() ...

where setQueryParams function look like this:

setQueryParams(page?: number, size?: number): {} {
const startFrom = page * size + 1;
const params = new HttpParams();
params.set('startFrom', startFrom.toString());
params.set('maxRecords', size.toString());
return params;

}

When the request comes to my backend query params are null, somehow they are not being passed over but why ? Is this not the right method or what ?

smoczyna
  • 489
  • 6
  • 18
  • are you using HttpClient? it looks like you are but can you please clarify? also, url parameters dont go in the headers, they go in the url – mast3rd3mon Aug 17 '18 at 08:21
  • Possible duplicate of [How to pass url arguments (query string) to a HTTP request on Angular?](https://stackoverflow.com/questions/34475523/how-to-pass-url-arguments-query-string-to-a-http-request-on-angular) – mrkernelpanic Aug 17 '18 at 08:22
  • The URL in my code is static and has no params. My intention is to call this URL with Query Parameters like this: http://localhost:7001/suds/pending-registration-finder/findAll?startFrom=5&maxRecords=10 – smoczyna Aug 17 '18 at 08:50

1 Answers1

-1

It just occurred that using HttpParams or URLSearchParams objects do not work at all. All tries with these 2 failed in my case. The only way is to build parameters explicitly like this:

setRequestParams(page?: number, size?: number): {} {
const startFrom = page * size + 1;
const params = {'startFrom': startFrom.toString(), 'maxRecords': size.toString()};
const options = {params: params};
return options;

}

Well I beleive this is a bug in Angular HttpClient.

smoczyna
  • 489
  • 6
  • 18