UNPKG

4.69 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 { RequestMethod, ResponseContentType } from './enums';
9import { Headers } from './headers';
10import { RequestOptionsArgs } from './interfaces';
11import { URLSearchParams } from './url_search_params';
12/**
13 * Creates a request options object to be optionally provided when instantiating a
14 * {@link Request}.
15 *
16 * This class is based on the `RequestInit` description in the [Fetch
17 * Spec](https://fetch.spec.whatwg.org/#requestinit).
18 *
19 * All values are null by default. Typical defaults can be found in the {@link BaseRequestOptions}
20 * class, which sub-classes `RequestOptions`.
21 *
22 * ```typescript
23 * import {RequestOptions, Request, RequestMethod} from '@angular/http';
24 *
25 * const options = new RequestOptions({
26 * method: RequestMethod.Post,
27 * url: 'https://google.com'
28 * });
29 * const req = new Request(options);
30 * console.log('req.method:', RequestMethod[req.method]); // Post
31 * console.log('options.url:', options.url); // https://google.com
32 * ```
33 *
34 * @deprecated see https://angular.io/guide/http
35 * @publicApi
36 */
37export declare class RequestOptions {
38 /**
39 * Http method with which to execute a {@link Request}.
40 * Acceptable methods are defined in the {@link RequestMethod} enum.
41 */
42 method: RequestMethod | string | null;
43 /**
44 * {@link Headers} to be attached to a {@link Request}.
45 */
46 headers: Headers | null;
47 /**
48 * Body to be used when creating a {@link Request}.
49 */
50 body: any;
51 /**
52 * Url with which to perform a {@link Request}.
53 */
54 url: string | null;
55 /**
56 * Search parameters to be included in a {@link Request}.
57 */
58 params: URLSearchParams;
59 /**
60 * @deprecated from 4.0.0. Use params instead.
61 */
62 /**
63 * @deprecated from 4.0.0. Use params instead.
64 */
65 search: URLSearchParams;
66 /**
67 * Enable use credentials for a {@link Request}.
68 */
69 withCredentials: boolean | null;
70 responseType: ResponseContentType | null;
71 constructor(opts?: RequestOptionsArgs);
72 /**
73 * Creates a copy of the `RequestOptions` instance, using the optional input as values to override
74 * existing values. This method will not change the values of the instance on which it is being
75 * called.
76 *
77 * Note that `headers` and `search` will override existing values completely if present in
78 * the `options` object. If these values should be merged, it should be done prior to calling
79 * `merge` on the `RequestOptions` instance.
80 *
81 * ```typescript
82 * import {RequestOptions, Request, RequestMethod} from '@angular/http';
83 *
84 * const options = new RequestOptions({
85 * method: RequestMethod.Post
86 * });
87 * const req = new Request(options.merge({
88 * url: 'https://google.com'
89 * }));
90 * console.log('req.method:', RequestMethod[req.method]); // Post
91 * console.log('options.url:', options.url); // null
92 * console.log('req.url:', req.url); // https://google.com
93 * ```
94 */
95 merge(options?: RequestOptionsArgs): RequestOptions;
96 private _mergeSearchParams;
97 private _parseParams;
98 private _appendParam;
99}
100/**
101 * Subclass of {@link RequestOptions}, with default values.
102 *
103 * Default values:
104 * * method: {@link RequestMethod RequestMethod.Get}
105 * * headers: empty {@link Headers} object
106 *
107 * This class could be extended and bound to the {@link RequestOptions} class
108 * when configuring an {@link Injector}, in order to override the default options
109 * used by {@link Http} to create and send {@link Request Requests}.
110 *
111 * ```typescript
112 * import {BaseRequestOptions, RequestOptions} from '@angular/http';
113 *
114 * class MyOptions extends BaseRequestOptions {
115 * search: string = 'coreTeam=true';
116 * }
117 *
118 * {provide: RequestOptions, useClass: MyOptions};
119 * ```
120 *
121 * The options could also be extended when manually creating a {@link Request}
122 * object.
123 *
124 * ```
125 * import {BaseRequestOptions, Request, RequestMethod} from '@angular/http';
126 *
127 * const options = new BaseRequestOptions();
128 * const req = new Request(options.merge({
129 * method: RequestMethod.Post,
130 * url: 'https://google.com'
131 * }));
132 * console.log('req.method:', RequestMethod[req.method]); // Post
133 * console.log('options.url:', options.url); // null
134 * console.log('req.url:', req.url); // https://google.com
135 * ```
136 *
137 * @deprecated see https://angular.io/guide/http
138 * @publicApi
139 */
140export declare class BaseRequestOptions extends RequestOptions {
141 constructor();
142}
143
\No newline at end of file