From ad40fcae7a7dd8270a5094f09af10f6f62291f97 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 26 Feb 2021 14:52:14 +0700 Subject: [PATCH] docs: improve documentation on how to pass a stringified parameter list to HttpClient (#41010) Fixes #40618 PR Close #41010 --- packages/common/http/src/client.ts | 9 +++++++++ packages/common/http/src/request.ts | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/packages/common/http/src/client.ts b/packages/common/http/src/client.ts index 3e18131aa3..ee5b434a37 100644 --- a/packages/common/http/src/client.ts +++ b/packages/common/http/src/client.ts @@ -74,6 +74,14 @@ function addBody( * return this.httpClient.request('GET', this.heroesUrl, {responseType:'json', params}); * } * ``` + * + * Alternatively, the parameter string can be used without invoking HttpParams + * by directly joining to the URL. + * ``` + * this.httpClient.request('GET', this.heroesUrl + '?' + 'name=term', {responseType:'json'}); + * ``` + * + * * ### JSONP Example * ``` * requestJsonp(url, callback = 'callback') { @@ -92,6 +100,7 @@ function addBody( * ``` * * @see [HTTP Guide](guide/http) + * @see [HTTP Request](api/common/http/HttpRequest) * * @publicApi */ diff --git a/packages/common/http/src/request.ts b/packages/common/http/src/request.ts index 0467aef812..6f45a5e3e6 100644 --- a/packages/common/http/src/request.ts +++ b/packages/common/http/src/request.ts @@ -119,6 +119,13 @@ export class HttpRequest { /** * Outgoing URL parameters. + * + * To pass a string representation of HTTP parameters in the URL-query-string format, + * the `HttpParamsOptions`' `fromString` may be used. For example: + * + * ``` + * new HttpParams({fromString: 'angular=awesome'}) + * ``` */ // TODO(issue/24571): remove '!'. readonly params!: HttpParams;