2015-04-28 23:07:55 -07:00
|
|
|
/// <reference path="../../typings/rx/rx.all.d.ts" />
|
|
|
|
|
|
|
|
import {
|
|
|
|
ReadyStates,
|
|
|
|
RequestModesOpts,
|
|
|
|
RequestMethods,
|
|
|
|
RequestCacheOpts,
|
|
|
|
RequestCredentialsOpts,
|
|
|
|
ResponseTypes
|
|
|
|
} from './enums';
|
|
|
|
import {Headers} from './headers';
|
|
|
|
import {URLSearchParams} from './url_search_params';
|
|
|
|
|
2015-06-13 19:48:40 -07:00
|
|
|
export interface IRequestOptions {
|
2015-04-28 23:07:55 -07:00
|
|
|
method?: RequestMethods;
|
|
|
|
headers?: Headers;
|
2015-06-13 15:49:05 -07:00
|
|
|
body?: URLSearchParams | FormData | Blob | string;
|
2015-04-28 23:07:55 -07:00
|
|
|
mode?: RequestModesOpts;
|
|
|
|
credentials?: RequestCredentialsOpts;
|
|
|
|
cache?: RequestCacheOpts;
|
|
|
|
}
|
|
|
|
|
2015-06-16 10:46:12 -07:00
|
|
|
export interface IRequest {
|
2015-04-28 23:07:55 -07:00
|
|
|
method: RequestMethods;
|
|
|
|
mode: RequestModesOpts;
|
|
|
|
credentials: RequestCredentialsOpts;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ResponseOptions {
|
|
|
|
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;
|
|
|
|
blob(): Blob;
|
|
|
|
arrayBuffer(): ArrayBuffer;
|
|
|
|
text(): string;
|
|
|
|
json(): Object;
|
|
|
|
}
|
|
|
|
|
2015-06-16 10:46:12 -07:00
|
|
|
export interface ConnectionBackend {
|
|
|
|
createConnection(observer: any, config: IRequest): Connection;
|
|
|
|
}
|
2015-04-28 23:07:55 -07:00
|
|
|
|
|
|
|
export interface Connection {
|
|
|
|
readyState: ReadyStates;
|
2015-06-16 10:46:12 -07:00
|
|
|
request: IRequest;
|
|
|
|
response: Rx.Subject<IResponse>;
|
2015-04-28 23:07:55 -07:00
|
|
|
dispose(): void;
|
|
|
|
}
|
|
|
|
|
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-16 10:46:12 -07:00
|
|
|
export interface IHttp { (url: string, options?: IRequestOptions): Rx.Observable<IResponse> }
|