1 import { Observable } from '../../Observable';
2 import { Subscriber } from '../../Subscriber';
3 import { TeardownLogic } from '../../types';
4 export interface AjaxRequest {
14 crossDomain?: boolean;
15 withCredentials?: boolean;
16 createXHR?: () => XMLHttpRequest;
17 progressSubscriber?: Subscriber<any>;
18 responseType?: string;
20 export interface AjaxCreationMethod {
21 (urlOrRequest: string | AjaxRequest): Observable<AjaxResponse>;
22 get(url: string, headers?: Object): Observable<AjaxResponse>;
23 post(url: string, body?: any, headers?: Object): Observable<AjaxResponse>;
24 put(url: string, body?: any, headers?: Object): Observable<AjaxResponse>;
25 patch(url: string, body?: any, headers?: Object): Observable<AjaxResponse>;
26 delete(url: string, headers?: Object): Observable<AjaxResponse>;
27 getJSON<T>(url: string, headers?: Object): Observable<T>;
29 export declare function ajaxGet(url: string, headers?: Object): AjaxObservable<AjaxResponse>;
30 export declare function ajaxPost(url: string, body?: any, headers?: Object): Observable<AjaxResponse>;
31 export declare function ajaxDelete(url: string, headers?: Object): Observable<AjaxResponse>;
32 export declare function ajaxPut(url: string, body?: any, headers?: Object): Observable<AjaxResponse>;
33 export declare function ajaxPatch(url: string, body?: any, headers?: Object): Observable<AjaxResponse>;
34 export declare function ajaxGetJSON<T>(url: string, headers?: Object): Observable<T>;
36 * We need this JSDoc comment for affecting ESDoc.
40 export declare class AjaxObservable<T> extends Observable<T> {
42 * Creates an observable for an Ajax request with either a request object with
43 * url, headers, etc or a string for a URL.
47 * import { ajax } from 'rxjs/ajax';
49 * const source1 = ajax('/products');
50 * const source2 = ajax({ url: 'products', method: 'GET' });
53 * @param {string|Object} request Can be one of the following:
54 * A string of the URL to make the Ajax call.
55 * An object with the following properties
56 * - url: URL of the request
57 * - body: The body of the request
58 * - method: Method of the request, such as GET, POST, PUT, PATCH, DELETE
59 * - async: Whether the request is async
60 * - headers: Optional headers
61 * - crossDomain: true if a cross domain request, else false
62 * - createXHR: a function to override if you need to use an alternate
63 * XMLHttpRequest implementation.
64 * - resultSelector: a function to use to alter the output value type of
65 * the Observable. Gets {@link AjaxResponse} as an argument.
66 * @return {Observable} An observable sequence containing the XMLHttpRequest.
72 static create: AjaxCreationMethod;
74 constructor(urlOrRequest: string | AjaxRequest);
75 /** @deprecated This is an internal implementation detail, do not use. */
76 _subscribe(subscriber: Subscriber<T>): TeardownLogic;
79 * We need this JSDoc comment for affecting ESDoc.
83 export declare class AjaxSubscriber<T> extends Subscriber<Event> {
87 constructor(destination: Subscriber<T>, request: AjaxRequest);
90 private serializeBody;
97 * A normalized AJAX response.
101 * @class AjaxResponse
103 export declare class AjaxResponse {
104 originalEvent: Event;
106 request: AjaxRequest;
107 /** @type {number} The HTTP status code */
109 /** @type {string|ArrayBuffer|Document|object|any} The response data */
111 /** @type {string} The raw responseText */
112 responseText: string;
113 /** @type {string} The responseType (e.g. 'json', 'arraybuffer', or 'xml') */
114 responseType: string;
115 constructor(originalEvent: Event, xhr: XMLHttpRequest, request: AjaxRequest);
117 export declare type AjaxErrorNames = 'AjaxError' | 'AjaxTimeoutError';
119 * A normalized AJAX error.
125 export interface AjaxError extends Error {
126 /** @type {XMLHttpRequest} The XHR instance associated with the error */
128 /** @type {AjaxRequest} The AjaxRequest associated with the error */
129 request: AjaxRequest;
130 /** @type {number} The HTTP status code */
132 /** @type {string} The responseType (e.g. 'json', 'arraybuffer', or 'xml') */
133 responseType: string;
134 /** @type {string|ArrayBuffer|Document|object|any} The response data */
137 export interface AjaxErrorCtor {
138 new (message: string, xhr: XMLHttpRequest, request: AjaxRequest): AjaxError;
140 export declare const AjaxError: AjaxErrorCtor;
141 export interface AjaxTimeoutError extends AjaxError {
143 export interface AjaxTimeoutErrorCtor {
144 new (xhr: XMLHttpRequest, request: AjaxRequest): AjaxTimeoutError;
149 * @class AjaxTimeoutError
151 export declare const AjaxTimeoutError: AjaxTimeoutErrorCtor;