1 import { AjaxObservable, AjaxCreationMethod } from './AjaxObservable';
3 * There is an ajax operator on the Rx object.
5 * It creates an observable for an Ajax request with either a request object with
6 * url, headers, etc or a string for a URL.
9 * ## Using ajax() to fetch the response object that is being returned from API.
11 * import { ajax } from 'rxjs/ajax';
12 * import { map, catchError } from 'rxjs/operators';
13 * import { of } from 'rxjs';
15 * const obs$ = ajax(`https://api.github.com/users?per_page=5`).pipe(
16 * map(userResponse => console.log('users: ', userResponse)),
17 * catchError(error => {
18 * console.log('error: ', error);
25 * ## Using ajax.getJSON() to fetch data from API.
27 * import { ajax } from 'rxjs/ajax';
28 * import { map, catchError } from 'rxjs/operators';
29 * import { of } from 'rxjs';
31 * const obs$ = ajax.getJSON(`https://api.github.com/users?per_page=5`).pipe(
32 * map(userResponse => console.log('users: ', userResponse)),
33 * catchError(error => {
34 * console.log('error: ', error);
41 * ## Using ajax() with object as argument and method POST with a two seconds delay.
43 * import { ajax } from 'rxjs/ajax';
44 * import { of } from 'rxjs';
46 * const users = ajax({
47 * url: 'https://httpbin.org/delay/2',
50 * 'Content-Type': 'application/json',
51 * 'rxjs-custom-header': 'Rxjs'
54 * rxjs: 'Hello World!'
57 * map(response => console.log('response: ', response)),
58 * catchError(error => {
59 * console.log('error: ', error);
66 * ## Using ajax() to fetch. An error object that is being returned from the request.
68 * import { ajax } from 'rxjs/ajax';
69 * import { map, catchError } from 'rxjs/operators';
70 * import { of } from 'rxjs';
72 * const obs$ = ajax(`https://api.github.com/404`).pipe(
73 * map(userResponse => console.log('users: ', userResponse)),
74 * catchError(error => {
75 * console.log('error: ', error);
82 export const ajax: AjaxCreationMethod = (() => AjaxObservable.create)();