MCPcopy Create free account
hub / github.com/angular/angular / request

Method request

packages/common/http/src/client.ts:457–603  ·  view source on GitHub ↗

* 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 = {},
  )

Source from the content-addressed store, hash-verified

455 *
456 */
457 request(
458 first: string | HttpRequest<any>,
459 url?: string,
460 options: {
461 body?: any;
462 observe?: 'body' | 'events' | 'response';
463 responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
464 } & HttpClientCommonOptions = {},
465 ): Observable<any> {
466 let req: HttpRequest<any>;
467 // First, check whether the primary argument is an instance of `HttpRequest`.
468 if (first instanceof HttpRequest) {
469 // It is. The other arguments must be undefined (per the signatures) and can be
470 // ignored.
471 req = first;
472 } else {
473 // It's a string, so it represents a URL. Construct a request based on it,
474 // and incorporate the remaining arguments (assuming `GET` unless a method is
475 // provided.
476
477 // Figure out the headers.
478 let headers: HttpHeaders | undefined = undefined;
479 if (options.headers instanceof HttpHeaders) {
480 headers = options.headers;
481 } else {
482 headers = new HttpHeaders(options.headers);
483 }
484
485 // Sort out parameters.
486 let params: HttpParams | undefined = undefined;
487 if (!!options.params) {
488 if (options.params instanceof HttpParams) {
489 params = options.params;
490 } else {
491 params = new HttpParams({fromObject: options.params} as HttpParamsOptions);
492 }
493 }
494 // Construct the request.
495 req = new HttpRequest(first, url!, options.body !== undefined ? options.body : null, {
496 headers,
497 context: options.context,
498 params,
499 reportProgress: options.reportProgress,
500 reportUploadProgress: options.reportUploadProgress,
501 reportDownloadProgress: options.reportDownloadProgress,
502 // By default, JSON is assumed to be returned for all calls.
503 responseType: options.responseType || 'json',
504 withCredentials: options.withCredentials,
505 transferCache: options.transferCache,
506 keepalive: options.keepalive,
507 priority: options.priority,
508 cache: options.cache,
509 mode: options.mode,
510 redirect: options.redirect,
511 credentials: options.credentials,
512 referrer: options.referrer,
513 referrerPolicy: options.referrerPolicy,
514 integrity: options.integrity,

Callers 15

deleteMethod · 0.95
getMethod · 0.95
headMethod · 0.95
jsonpMethod · 0.95
optionsMethod · 0.95
patchMethod · 0.95
postMethod · 0.95
putMethod · 0.95
client_spec.tsFile · 0.45
makeRequestAndExpectOneFunction · 0.45
makeRequestAndExpectNoneFunction · 0.45

Calls 1

handleMethod · 0.65

Tested by

no test coverage detected