2015-08-25 08:27:59 +00:00
|
|
|
import {ReadyStates, RequestMethods, ResponseTypes} from './enums';
|
2015-04-29 06:07:55 +00:00
|
|
|
import {Headers} from './headers';
|
2015-09-10 22:25:36 +00:00
|
|
|
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
|
2015-08-20 21:28:25 +00:00
|
|
|
import {EventEmitter} from 'angular2/src/core/facade/async';
|
2015-06-19 19:14:12 +00:00
|
|
|
import {Request} from './static_request';
|
2015-09-25 10:23:05 +00:00
|
|
|
import {URLSearchParams} from './url_search_params';
|
2015-06-19 19:14:12 +00:00
|
|
|
|
2015-06-24 07:27:07 +00:00
|
|
|
/**
|
|
|
|
|
* Abstract class from which real backends are derived.
|
|
|
|
|
*
|
|
|
|
|
* The primary purpose of a `ConnectionBackend` is to create new connections to fulfill a given
|
|
|
|
|
* {@link Request}.
|
|
|
|
|
*/
|
2015-10-06 13:53:39 +00:00
|
|
|
export abstract class ConnectionBackend { abstract createConnection(request: any): Connection; }
|
2015-06-19 19:14:12 +00:00
|
|
|
|
2015-06-24 07:27:07 +00:00
|
|
|
/**
|
|
|
|
|
* Abstract class from which real connections are derived.
|
|
|
|
|
*/
|
2015-09-25 21:48:17 +00:00
|
|
|
export abstract class Connection {
|
2015-06-19 19:14:12 +00:00
|
|
|
readyState: ReadyStates;
|
|
|
|
|
request: Request;
|
2015-10-01 23:04:20 +00:00
|
|
|
response: any; // TODO: generic of <Response>;
|
2015-06-19 19:14:12 +00:00
|
|
|
}
|
2015-04-29 06:07:55 +00:00
|
|
|
|
2015-06-24 07:27:07 +00:00
|
|
|
/**
|
|
|
|
|
* Interface for options to construct a Request, based on
|
|
|
|
|
* [RequestInit](https://fetch.spec.whatwg.org/#requestinit) from the Fetch spec.
|
|
|
|
|
*/
|
2015-09-07 05:14:19 +00:00
|
|
|
export type RequestOptionsArgs = {
|
2015-06-19 19:14:12 +00:00
|
|
|
url?: string;
|
2015-09-21 07:46:16 +00:00
|
|
|
method?: string | RequestMethods;
|
2015-07-13 18:47:10 +00:00
|
|
|
search?: string | URLSearchParams;
|
2015-04-29 06:07:55 +00:00
|
|
|
headers?: Headers;
|
2015-06-19 19:14:12 +00:00
|
|
|
// TODO: Support Blob, ArrayBuffer, JSON, URLSearchParams, FormData
|
|
|
|
|
body?: string;
|
2015-04-29 06:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
2015-06-24 07:27:07 +00:00
|
|
|
/**
|
|
|
|
|
* Interface for options to construct a Response, based on
|
|
|
|
|
* [ResponseInit](https://fetch.spec.whatwg.org/#responseinit) from the Fetch spec.
|
|
|
|
|
*/
|
2015-09-07 05:14:19 +00:00
|
|
|
export type ResponseOptionsArgs = {
|
2015-06-19 19:14:12 +00:00
|
|
|
// TODO: Support Blob, ArrayBuffer, JSON
|
|
|
|
|
body?: string | Object | FormData;
|
2015-04-29 06:07:55 +00:00
|
|
|
status?: number;
|
|
|
|
|
statusText?: string;
|
2015-06-24 07:27:07 +00:00
|
|
|
headers?: Headers;
|
2015-04-29 06:07:55 +00:00
|
|
|
type?: ResponseTypes;
|
|
|
|
|
url?: string;
|
|
|
|
|
}
|