* Constructs an observable for a generic HTTP request that, when subscribed, * fires the request through the chain of registered interceptors and on to the * server. * * You can pass an `HttpRequest` directly as the only parameter. In this case, * the call returns an observable of the
(
first: string | HttpRequest<any>,
url?: string,
options: {
body?: any;
observe?: 'body' | 'events' | 'response';
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
} & HttpClientCommonOptions = {},
)
| 463 | * |
| 464 | */ |
| 465 | request( |
| 466 | first: string | HttpRequest<any>, |
| 467 | url?: string, |
| 468 | options: { |
| 469 | body?: any; |
| 470 | observe?: 'body' | 'events' | 'response'; |
| 471 | responseType?: 'arraybuffer' | 'blob' | 'json' | 'text'; |
| 472 | } & HttpClientCommonOptions = {}, |
| 473 | ): Observable<any> { |
| 474 | let req: HttpRequest<any>; |
| 475 | // First, check whether the primary argument is an instance of `HttpRequest`. |
| 476 | if (first instanceof HttpRequest) { |
| 477 | // It is. The other arguments must be undefined (per the signatures) and can be |
| 478 | // ignored. |
| 479 | req = first; |
| 480 | } else { |
| 481 | // It's a string, so it represents a URL. Construct a request based on it, |
| 482 | // and incorporate the remaining arguments (assuming `GET` unless a method is |
| 483 | // provided. |
| 484 | |
| 485 | // Figure out the headers. |
| 486 | let headers: HttpHeaders | undefined = undefined; |
| 487 | if (options.headers instanceof HttpHeaders) { |
| 488 | headers = options.headers; |
| 489 | } else { |
| 490 | headers = new HttpHeaders(options.headers); |
| 491 | } |
| 492 | |
| 493 | // Sort out parameters. |
| 494 | let params: HttpParams | undefined = undefined; |
| 495 | if (!!options.params) { |
| 496 | if (options.params instanceof HttpParams) { |
| 497 | params = options.params; |
| 498 | } else { |
| 499 | params = new HttpParams({fromObject: options.params} as HttpParamsOptions); |
| 500 | } |
| 501 | } |
| 502 | // Construct the request. |
| 503 | req = new HttpRequest(first, url!, options.body !== undefined ? options.body : null, { |
| 504 | headers, |
| 505 | context: options.context, |
| 506 | params, |
| 507 | reportProgress: options.reportProgress, |
| 508 | reportUploadProgress: options.reportUploadProgress, |
| 509 | reportDownloadProgress: options.reportDownloadProgress, |
| 510 | // By default, JSON is assumed to be returned for all calls. |
| 511 | responseType: options.responseType || 'json', |
| 512 | withCredentials: options.withCredentials, |
| 513 | transferCache: options.transferCache, |
| 514 | keepalive: options.keepalive, |
| 515 | priority: options.priority, |
| 516 | cache: options.cache, |
| 517 | mode: options.mode, |
| 518 | redirect: options.redirect, |
| 519 | credentials: options.credentials, |
| 520 | referrer: options.referrer, |
| 521 | referrerPolicy: options.referrerPolicy, |
| 522 | integrity: options.integrity, |
no test coverage detected