UNPKG

angular2

Version:

Angular 2 - a web framework for modern web apps

58 lines (57 loc) 2.11 kB
import { ConnectionBackend, Connection } from '../interfaces'; import { ReadyState } from '../enums'; import { Request } from '../static_request'; import { Response } from '../static_response'; import { ResponseOptions } from '../base_response_options'; import { BrowserXhr } from './browser_xhr'; import { Observable } from 'rxjs/Observable'; /** * Creates connections using `XMLHttpRequest`. Given a fully-qualified * request, an `XHRConnection` will immediately create an `XMLHttpRequest` object and send the * request. * * This class would typically not be created or interacted with directly inside applications, though * the {@link MockConnection} may be interacted with in tests. */ export declare class XHRConnection implements Connection { request: Request; /** * Response {@link EventEmitter} which emits a single {@link Response} value on load event of * `XMLHttpRequest`. */ response: Observable<Response>; readyState: ReadyState; constructor(req: Request, browserXHR: BrowserXhr, baseResponseOptions?: ResponseOptions); } /** * Creates {@link XHRConnection} instances. * * This class would typically not be used by end users, but could be * overridden if a different backend implementation should be used, * such as in a node backend. * * ### Example * * ``` * import {Http, MyNodeBackend, HTTP_PROVIDERS, BaseRequestOptions} from 'angular2/http'; * @Component({ * viewProviders: [ * HTTP_PROVIDERS, * provide(Http, {useFactory: (backend, options) => { * return new Http(backend, options); * }, deps: [MyNodeBackend, BaseRequestOptions]})] * }) * class MyComponent { * constructor(http:Http) { * http.request('people.json').subscribe(res => this.people = res.json()); * } * } * ``` * **/ export declare class XHRBackend implements ConnectionBackend { private _browserXHR; private _baseResponseOptions; constructor(_browserXHR: BrowserXhr, _baseResponseOptions: ResponseOptions); createConnection(request: Request): XHRConnection; }