UNPKG

9.12 kBTypeScriptView Raw
1import { PartialObserver } from '../types';
2/**
3 * Valid Ajax direction types. Prefixes the event `type` in the
4 * {@link AjaxResponse} object with "upload_" for events related
5 * to uploading and "download_" for events related to downloading.
6 */
7export declare type AjaxDirection = 'upload' | 'download';
8export declare type ProgressEventType = 'loadstart' | 'progress' | 'load';
9export declare type AjaxResponseType = `${AjaxDirection}_${ProgressEventType}`;
10/**
11 * The object containing values RxJS used to make the HTTP request.
12 *
13 * This is provided in {@link AjaxError} instances as the `request`
14 * object.
15 */
16export interface AjaxRequest {
17 /**
18 * The URL requested.
19 */
20 url: string;
21 /**
22 * The body to send over the HTTP request.
23 */
24 body?: any;
25 /**
26 * The HTTP method used to make the HTTP request.
27 */
28 method: string;
29 /**
30 * Whether or not the request was made asynchronously.
31 */
32 async: boolean;
33 /**
34 * The headers sent over the HTTP request.
35 */
36 headers: Readonly<Record<string, any>>;
37 /**
38 * The timeout value used for the HTTP request.
39 * Note: this is only honored if the request is asynchronous (`async` is `true`).
40 */
41 timeout: number;
42 /**
43 * The user credentials user name sent with the HTTP request.
44 */
45 user?: string;
46 /**
47 * The user credentials password sent with the HTTP request.
48 */
49 password?: string;
50 /**
51 * Whether or not the request was a CORS request.
52 */
53 crossDomain: boolean;
54 /**
55 * Whether or not a CORS request was sent with credentials.
56 * If `false`, will also ignore cookies in the CORS response.
57 */
58 withCredentials: boolean;
59 /**
60 * The [`responseType`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType) set before sending the request.
61 */
62 responseType: XMLHttpRequestResponseType;
63}
64/**
65 * Configuration for the {@link ajax} creation function.
66 */
67export interface AjaxConfig {
68 /** The address of the resource to request via HTTP. */
69 url: string;
70 /**
71 * The body of the HTTP request to send.
72 *
73 * This is serialized, by default, based off of the value of the `"content-type"` header.
74 * For example, if the `"content-type"` is `"application/json"`, the body will be serialized
75 * as JSON. If the `"content-type"` is `"application/x-www-form-urlencoded"`, whatever object passed
76 * to the body will be serialized as URL, using key-value pairs based off of the keys and values of the object.
77 * In all other cases, the body will be passed directly.
78 */
79 body?: any;
80 /**
81 * Whether or not to send the request asynchronously. Defaults to `true`.
82 * If set to `false`, this will block the thread until the AJAX request responds.
83 */
84 async?: boolean;
85 /**
86 * The HTTP Method to use for the request. Defaults to "GET".
87 */
88 method?: string;
89 /**
90 * The HTTP headers to apply.
91 *
92 * Note that, by default, RxJS will add the following headers under certain conditions:
93 *
94 * 1. If the `"content-type"` header is **NOT** set, and the `body` is [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData),
95 * a `"content-type"` of `"application/x-www-form-urlencoded; charset=UTF-8"` will be set automatically.
96 * 2. If the `"x-requested-with"` header is **NOT** set, and the `crossDomain` configuration property is **NOT** explicitly set to `true`,
97 * (meaning it is not a CORS request), a `"x-requested-with"` header with a value of `"XMLHttpRequest"` will be set automatically.
98 * This header is generally meaningless, and is set by libraries and frameworks using `XMLHttpRequest` to make HTTP requests.
99 */
100 headers?: Readonly<Record<string, any>>;
101 /**
102 * The time to wait before causing the underlying XMLHttpRequest to timeout. This is only honored if the
103 * `async` configuration setting is unset or set to `true`. Defaults to `0`, which is idiomatic for "never timeout".
104 */
105 timeout?: number;
106 /** The user credentials user name to send with the HTTP request */
107 user?: string;
108 /** The user credentials password to send with the HTTP request*/
109 password?: string;
110 /**
111 * Whether or not to send the HTTP request as a CORS request.
112 * Defaults to `false`.
113 *
114 * @deprecated Will be removed in version 8. Cross domain requests and what creates a cross
115 * domain request, are dictated by the browser, and a boolean that forces it to be cross domain
116 * does not make sense. If you need to force cross domain, make sure you're making a secure request,
117 * then add a custom header to the request or use `withCredentials`. For more information on what
118 * triggers a cross domain request, see the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Requests_with_credentials).
119 * In particular, the section on [Simple Requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#Simple_requests) is useful
120 * for understanding when CORS will not be used.
121 */
122 crossDomain?: boolean;
123 /**
124 * To send user credentials in a CORS request, set to `true`. To exclude user credentials from
125 * a CORS request, _OR_ when cookies are to be ignored by the CORS response, set to `false`.
126 *
127 * Defaults to `false`.
128 */
129 withCredentials?: boolean;
130 /**
131 * The name of your site's XSRF cookie.
132 */
133 xsrfCookieName?: string;
134 /**
135 * The name of a custom header that you can use to send your XSRF cookie.
136 */
137 xsrfHeaderName?: string;
138 /**
139 * Can be set to change the response type.
140 * Valid values are `"arraybuffer"`, `"blob"`, `"document"`, `"json"`, and `"text"`.
141 * Note that the type of `"document"` (such as an XML document) is ignored if the global context is
142 * not `Window`.
143 *
144 * Defaults to `"json"`.
145 */
146 responseType?: XMLHttpRequestResponseType;
147 /**
148 * An optional factory used to create the XMLHttpRequest object used to make the AJAX request.
149 * This is useful in environments that lack `XMLHttpRequest`, or in situations where you
150 * wish to override the default `XMLHttpRequest` for some reason.
151 *
152 * If not provided, the `XMLHttpRequest` in global scope will be used.
153 *
154 * NOTE: This AJAX implementation relies on the built-in serialization and setting
155 * of Content-Type headers that is provided by standards-compliant XMLHttpRequest implementations,
156 * be sure any implementation you use meets that standard.
157 */
158 createXHR?: () => XMLHttpRequest;
159 /**
160 * An observer for watching the upload progress of an HTTP request. Will
161 * emit progress events, and completes on the final upload load event, will error for
162 * any XHR error or timeout.
163 *
164 * This will **not** error for errored status codes. Rather, it will always _complete_ when
165 * the HTTP response comes back.
166 *
167 * @deprecated If you're looking for progress events, use {@link includeDownloadProgress} and
168 * {@link includeUploadProgress} instead. Will be removed in v8.
169 */
170 progressSubscriber?: PartialObserver<ProgressEvent>;
171 /**
172 * If `true`, will emit all download progress and load complete events as {@link AjaxResponse}
173 * from the observable. The final download event will also be emitted as a {@link AjaxResponse}.
174 *
175 * If both this and {@link includeUploadProgress} are `false`, then only the {@link AjaxResponse} will
176 * be emitted from the resulting observable.
177 */
178 includeDownloadProgress?: boolean;
179 /**
180 * If `true`, will emit all upload progress and load complete events as {@link AjaxResponse}
181 * from the observable. The final download event will also be emitted as a {@link AjaxResponse}.
182 *
183 * If both this and {@link includeDownloadProgress} are `false`, then only the {@link AjaxResponse} will
184 * be emitted from the resulting observable.
185 */
186 includeUploadProgress?: boolean;
187 /**
188 * Query string parameters to add to the URL in the request.
189 * <em>This will require a polyfill for `URL` and `URLSearchParams` in Internet Explorer!</em>
190 *
191 * Accepts either a query string, a `URLSearchParams` object, a dictionary of key/value pairs, or an
192 * array of key/value entry tuples. (Essentially, it takes anything that `new URLSearchParams` would normally take).
193 *
194 * If, for some reason you have a query string in the `url` argument, this will append to the query string in the url,
195 * but it will also overwrite the value of any keys that are an exact match. In other words, a url of `/test?a=1&b=2`,
196 * with queryParams of `{ b: 5, c: 6 }` will result in a url of roughly `/test?a=1&b=5&c=6`.
197 */
198 queryParams?: string | URLSearchParams | Record<string, string | number | boolean | string[] | number[] | boolean[]> | [string, string | number | boolean | string[] | number[] | boolean[]][];
199}
200//# sourceMappingURL=types.d.ts.map
\No newline at end of file