2015-06-29 15:30:48 -07:00
|
|
|
/// <reference path="../../typings/rx/rx.d.ts" />
|
2015-04-28 23:07:55 -07:00
|
|
|
|
|
|
|
import {
|
|
|
|
ReadyStates,
|
|
|
|
RequestModesOpts,
|
|
|
|
RequestMethods,
|
|
|
|
RequestCacheOpts,
|
|
|
|
RequestCredentialsOpts,
|
|
|
|
ResponseTypes
|
|
|
|
} from './enums';
|
|
|
|
import {Headers} from './headers';
|
2015-06-19 12:14:12 -07:00
|
|
|
import {BaseException} from 'angular2/src/facade/lang';
|
|
|
|
import {EventEmitter} from 'angular2/src/facade/async';
|
|
|
|
import {Request} from './static_request';
|
|
|
|
|
|
|
|
export class ConnectionBackend {
|
|
|
|
constructor() {}
|
|
|
|
createConnection(request: any): Connection { throw new BaseException('Abstract!'); }
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Connection {
|
|
|
|
readyState: ReadyStates;
|
|
|
|
request: Request;
|
|
|
|
response: EventEmitter; //<IResponse>;
|
|
|
|
dispose(): void { throw new BaseException('Abstract!'); }
|
|
|
|
}
|
2015-04-28 23:07:55 -07:00
|
|
|
|
2015-06-13 19:48:40 -07:00
|
|
|
export interface IRequestOptions {
|
2015-06-19 12:14:12 -07:00
|
|
|
url?: string;
|
2015-04-28 23:07:55 -07:00
|
|
|
method?: RequestMethods;
|
|
|
|
headers?: Headers;
|
2015-06-19 12:14:12 -07:00
|
|
|
// TODO: Support Blob, ArrayBuffer, JSON, URLSearchParams, FormData
|
|
|
|
body?: string;
|
2015-04-28 23:07:55 -07:00
|
|
|
mode?: RequestModesOpts;
|
|
|
|
credentials?: RequestCredentialsOpts;
|
|
|
|
cache?: RequestCacheOpts;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ResponseOptions {
|
2015-06-19 12:14:12 -07:00
|
|
|
// TODO: Support Blob, ArrayBuffer, JSON
|
|
|
|
body?: string | Object | FormData;
|
2015-04-28 23:07:55 -07:00
|
|
|
status?: number;
|
|
|
|
statusText?: string;
|
|
|
|
headers?: Headers | Object;
|
|
|
|
type?: ResponseTypes;
|
|
|
|
url?: string;
|
|
|
|
}
|
|
|
|
|
2015-06-16 10:46:12 -07:00
|
|
|
export interface IResponse {
|
2015-04-28 23:07:55 -07:00
|
|
|
headers: Headers;
|
|
|
|
ok: boolean;
|
|
|
|
status: number;
|
|
|
|
statusText: string;
|
|
|
|
type: ResponseTypes;
|
|
|
|
url: string;
|
|
|
|
totalBytes: number;
|
|
|
|
bytesLoaded: number;
|
2015-06-19 12:14:12 -07:00
|
|
|
blob(): any; // TODO: Blob
|
|
|
|
arrayBuffer(): any; // TODO: ArrayBuffer
|
2015-04-28 23:07:55 -07:00
|
|
|
text(): string;
|
|
|
|
json(): Object;
|
|
|
|
}
|
|
|
|
|
2015-06-09 15:18:57 -07:00
|
|
|
/**
|
|
|
|
* Provides an interface to provide type information for {@link HttpFactory} when injecting.
|
|
|
|
*
|
|
|
|
* #Example
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* * import {httpInjectables, HttpFactory, IHttp} from 'angular2/http';
|
|
|
|
* @Component({
|
|
|
|
* appInjector: [httpInjectables]
|
|
|
|
* })
|
|
|
|
* @View({
|
|
|
|
* templateUrl: 'people.html'
|
|
|
|
* })
|
|
|
|
* class MyComponent {
|
|
|
|
* constructor(@Inject(HttpFactory) http:IHttp) {
|
|
|
|
* http('people.json').subscribe(res => this.people = res.json());
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
*/
|
2015-04-28 23:07:55 -07:00
|
|
|
// Prefixed as IHttp because used in conjunction with Http class, but interface is callable
|
|
|
|
// constructor(@Inject(Http) http:IHttp)
|
2015-06-19 12:14:12 -07:00
|
|
|
export interface IHttp { (url: string, options?: IRequestOptions): EventEmitter }
|