UNPKG

2.89 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google Inc. All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { Body } from './body';
9import { ContentType, RequestMethod, ResponseContentType } from './enums';
10import { Headers } from './headers';
11import { RequestArgs } from './interfaces';
12/**
13 * Creates `Request` instances from provided values.
14 *
15 * The Request's interface is inspired by the Request constructor defined in the [Fetch
16 * Spec](https://fetch.spec.whatwg.org/#request-class),
17 * but is considered a static value whose body can be accessed many times. There are other
18 * differences in the implementation, but this is the most significant.
19 *
20 * `Request` instances are typically created by higher-level classes, like {@link Http} and
21 * {@link Jsonp}, but it may occasionally be useful to explicitly create `Request` instances.
22 * One such example is when creating services that wrap higher-level services, like {@link Http},
23 * where it may be useful to generate a `Request` with arbitrary headers and search params.
24 *
25 * ```typescript
26 * import {Injectable, Injector} from '@angular/core';
27 * import {HTTP_PROVIDERS, Http, Request, RequestMethod} from '@angular/http';
28 *
29 * @Injectable()
30 * class AutoAuthenticator {
31 * constructor(public http:Http) {}
32 * request(url:string) {
33 * return this.http.request(new Request({
34 * method: RequestMethod.Get,
35 * url: url,
36 * search: 'password=123'
37 * }));
38 * }
39 * }
40 *
41 * var injector = Injector.resolveAndCreate([HTTP_PROVIDERS, AutoAuthenticator]);
42 * var authenticator = injector.get(AutoAuthenticator);
43 * authenticator.request('people.json').subscribe(res => {
44 * //URL should have included '?password=123'
45 * console.log('people', res.json());
46 * });
47 * ```
48 *
49 * @deprecated see https://angular.io/guide/http
50 * @publicApi
51 */
52export declare class Request extends Body {
53 /**
54 * Http method with which to perform the request.
55 */
56 method: RequestMethod;
57 /**
58 * {@link Headers} instance
59 */
60 headers: Headers;
61 /** Url of the remote resource */
62 url: string;
63 /** Type of the request body **/
64 private contentType;
65 /** Enable use credentials */
66 withCredentials: boolean;
67 /** Buffer to store the response */
68 responseType: ResponseContentType;
69 constructor(requestOptions: RequestArgs);
70 /**
71 * Returns the content type enum based on header options.
72 */
73 detectContentType(): ContentType;
74 /**
75 * Returns the content type of request's body based on its type.
76 */
77 detectContentTypeFromBody(): ContentType;
78 /**
79 * Returns the request's body according to its type. If body is undefined, return
80 * null.
81 */
82 getBody(): any;
83}
84export declare const ArrayBuffer: ArrayBufferConstructor;