Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AjaxObservable.d.ts 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { Observable } from '../../Observable';
  2. import { Subscriber } from '../../Subscriber';
  3. import { TeardownLogic } from '../../types';
  4. export interface AjaxRequest {
  5. url?: string;
  6. body?: any;
  7. user?: string;
  8. async?: boolean;
  9. method?: string;
  10. headers?: Object;
  11. timeout?: number;
  12. password?: string;
  13. hasContent?: boolean;
  14. crossDomain?: boolean;
  15. withCredentials?: boolean;
  16. createXHR?: () => XMLHttpRequest;
  17. progressSubscriber?: Subscriber<any>;
  18. responseType?: string;
  19. }
  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>;
  28. }
  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>;
  35. /**
  36. * We need this JSDoc comment for affecting ESDoc.
  37. * @extends {Ignored}
  38. * @hide true
  39. */
  40. export declare class AjaxObservable<T> extends Observable<T> {
  41. /**
  42. * Creates an observable for an Ajax request with either a request object with
  43. * url, headers, etc or a string for a URL.
  44. *
  45. * ## Example
  46. * ```ts
  47. * import { ajax } from 'rxjs/ajax';
  48. *
  49. * const source1 = ajax('/products');
  50. * const source2 = ajax({ url: 'products', method: 'GET' });
  51. * ```
  52. *
  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.
  67. * @static true
  68. * @name ajax
  69. * @owner Observable
  70. * @nocollapse
  71. */
  72. static create: AjaxCreationMethod;
  73. private request;
  74. constructor(urlOrRequest: string | AjaxRequest);
  75. /** @deprecated This is an internal implementation detail, do not use. */
  76. _subscribe(subscriber: Subscriber<T>): TeardownLogic;
  77. }
  78. /**
  79. * We need this JSDoc comment for affecting ESDoc.
  80. * @ignore
  81. * @extends {Ignored}
  82. */
  83. export declare class AjaxSubscriber<T> extends Subscriber<Event> {
  84. request: AjaxRequest;
  85. private xhr;
  86. private done;
  87. constructor(destination: Subscriber<T>, request: AjaxRequest);
  88. next(e: Event): void;
  89. private send;
  90. private serializeBody;
  91. private setHeaders;
  92. private getHeader;
  93. private setupEvents;
  94. unsubscribe(): void;
  95. }
  96. /**
  97. * A normalized AJAX response.
  98. *
  99. * @see {@link ajax}
  100. *
  101. * @class AjaxResponse
  102. */
  103. export declare class AjaxResponse {
  104. originalEvent: Event;
  105. xhr: XMLHttpRequest;
  106. request: AjaxRequest;
  107. /** @type {number} The HTTP status code */
  108. status: number;
  109. /** @type {string|ArrayBuffer|Document|object|any} The response data */
  110. response: any;
  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);
  116. }
  117. export declare type AjaxErrorNames = 'AjaxError' | 'AjaxTimeoutError';
  118. /**
  119. * A normalized AJAX error.
  120. *
  121. * @see {@link ajax}
  122. *
  123. * @class AjaxError
  124. */
  125. export interface AjaxError extends Error {
  126. /** @type {XMLHttpRequest} The XHR instance associated with the error */
  127. xhr: XMLHttpRequest;
  128. /** @type {AjaxRequest} The AjaxRequest associated with the error */
  129. request: AjaxRequest;
  130. /** @type {number} The HTTP status code */
  131. status: number;
  132. /** @type {string} The responseType (e.g. 'json', 'arraybuffer', or 'xml') */
  133. responseType: string;
  134. /** @type {string|ArrayBuffer|Document|object|any} The response data */
  135. response: any;
  136. }
  137. export interface AjaxErrorCtor {
  138. new (message: string, xhr: XMLHttpRequest, request: AjaxRequest): AjaxError;
  139. }
  140. export declare const AjaxError: AjaxErrorCtor;
  141. export interface AjaxTimeoutError extends AjaxError {
  142. }
  143. export interface AjaxTimeoutErrorCtor {
  144. new (xhr: XMLHttpRequest, request: AjaxRequest): AjaxTimeoutError;
  145. }
  146. /**
  147. * @see {@link ajax}
  148. *
  149. * @class AjaxTimeoutError
  150. */
  151. export declare const AjaxTimeoutError: AjaxTimeoutErrorCtor;