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