http.d.ts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. export { Request } from './src/http/static_request';
  2. export { Response } from './src/http/static_response';
  3. export { RequestOptionsArgs, ResponseOptionsArgs, Connection, ConnectionBackend } from './src/http/interfaces';
  4. export { BrowserXhr } from './src/http/backends/browser_xhr';
  5. export { BaseRequestOptions, RequestOptions } from './src/http/base_request_options';
  6. export { BaseResponseOptions, ResponseOptions } from './src/http/base_response_options';
  7. export { XHRBackend, XHRConnection } from './src/http/backends/xhr_backend';
  8. export { JSONPBackend, JSONPConnection } from './src/http/backends/jsonp_backend';
  9. export { Http, Jsonp } from './src/http/http';
  10. export { Headers } from './src/http/headers';
  11. export { ResponseType, ReadyState, RequestMethod } from './src/http/enums';
  12. export { URLSearchParams } from './src/http/url_search_params';
  13. /**
  14. * Provides a basic set of injectables to use the {@link Http} service in any application.
  15. *
  16. * The `HTTP_PROVIDERS` should be included either in a component's injector,
  17. * or in the root injector when bootstrapping an application.
  18. *
  19. * ### Example ([live demo](http://plnkr.co/edit/snj7Nv?p=preview))
  20. *
  21. * ```
  22. * import {Component} from 'angular2/core';
  23. * import {bootstrap} from 'angular2/platform/browser';
  24. * import {NgFor} from 'angular2/common';
  25. * import {HTTP_PROVIDERS, Http} from 'angular2/http';
  26. *
  27. * @Component({
  28. * selector: 'app',
  29. * providers: [HTTP_PROVIDERS],
  30. * template: `
  31. * <div>
  32. * <h1>People</h1>
  33. * <ul>
  34. * <li *ngFor="#person of people">
  35. * {{person.name}}
  36. * </li>
  37. * </ul>
  38. * </div>
  39. * `,
  40. * directives: [NgFor]
  41. * })
  42. * export class App {
  43. * people: Object[];
  44. * constructor(http:Http) {
  45. * http.get('people.json').subscribe(res => {
  46. * this.people = res.json();
  47. * });
  48. * }
  49. * active:boolean = false;
  50. * toggleActiveState() {
  51. * this.active = !this.active;
  52. * }
  53. * }
  54. *
  55. * bootstrap(App)
  56. * .catch(err => console.error(err));
  57. * ```
  58. *
  59. * The primary public API included in `HTTP_PROVIDERS` is the {@link Http} class.
  60. * However, other providers required by `Http` are included,
  61. * which may be beneficial to override in certain cases.
  62. *
  63. * The providers included in `HTTP_PROVIDERS` include:
  64. * * {@link Http}
  65. * * {@link XHRBackend}
  66. * * `BrowserXHR` - Private factory to create `XMLHttpRequest` instances
  67. * * {@link RequestOptions} - Bound to {@link BaseRequestOptions} class
  68. * * {@link ResponseOptions} - Bound to {@link BaseResponseOptions} class
  69. *
  70. * There may be cases where it makes sense to extend the base request options,
  71. * such as to add a search string to be appended to all URLs.
  72. * To accomplish this, a new provider for {@link RequestOptions} should
  73. * be added in the same injector as `HTTP_PROVIDERS`.
  74. *
  75. * ### Example ([live demo](http://plnkr.co/edit/aCMEXi?p=preview))
  76. *
  77. * ```
  78. * import {provide} from 'angular2/core';
  79. * import {bootstrap} from 'angular2/platform/browser';
  80. * import {HTTP_PROVIDERS, BaseRequestOptions, RequestOptions} from 'angular2/http';
  81. *
  82. * class MyOptions extends BaseRequestOptions {
  83. * search: string = 'coreTeam=true';
  84. * }
  85. *
  86. * bootstrap(App, [HTTP_PROVIDERS, provide(RequestOptions, {useClass: MyOptions})])
  87. * .catch(err => console.error(err));
  88. * ```
  89. *
  90. * Likewise, to use a mock backend for unit tests, the {@link XHRBackend}
  91. * provider should be bound to {@link MockBackend}.
  92. *
  93. * ### Example ([live demo](http://plnkr.co/edit/7LWALD?p=preview))
  94. *
  95. * ```
  96. * import {provide} from 'angular2/core';
  97. * import {bootstrap} from 'angular2/platform/browser';
  98. * import {HTTP_PROVIDERS, Http, Response, XHRBackend} from 'angular2/http';
  99. * import {MockBackend} from 'angular2/http/testing';
  100. *
  101. * var people = [{name: 'Jeff'}, {name: 'Tobias'}];
  102. *
  103. * var injector = Injector.resolveAndCreate([
  104. * HTTP_PROVIDERS,
  105. * MockBackend,
  106. * provide(XHRBackend, {useExisting: MockBackend})
  107. * ]);
  108. * var http = injector.get(Http);
  109. * var backend = injector.get(MockBackend);
  110. *
  111. * // Listen for any new requests
  112. * backend.connections.observer({
  113. * next: connection => {
  114. * var response = new Response({body: people});
  115. * setTimeout(() => {
  116. * // Send a response to the request
  117. * connection.mockRespond(response);
  118. * });
  119. * });
  120. *
  121. * http.get('people.json').observer({
  122. * next: res => {
  123. * // Response came from mock backend
  124. * console.log('first person', res.json()[0].name);
  125. * }
  126. * });
  127. * ```
  128. */
  129. export declare const HTTP_PROVIDERS: any[];
  130. /**
  131. * See {@link HTTP_PROVIDERS} instead.
  132. *
  133. * @deprecated
  134. */
  135. export declare const HTTP_BINDINGS: any[];
  136. /**
  137. * Provides a basic set of providers to use the {@link Jsonp} service in any application.
  138. *
  139. * The `JSONP_PROVIDERS` should be included either in a component's injector,
  140. * or in the root injector when bootstrapping an application.
  141. *
  142. * ### Example ([live demo](http://plnkr.co/edit/vmeN4F?p=preview))
  143. *
  144. * ```
  145. * import {Component} from 'angular2/core';
  146. * import {NgFor} from 'angular2/common';
  147. * import {JSONP_PROVIDERS, Jsonp} from 'angular2/http';
  148. *
  149. * @Component({
  150. * selector: 'app',
  151. * providers: [JSONP_PROVIDERS],
  152. * template: `
  153. * <div>
  154. * <h1>People</h1>
  155. * <ul>
  156. * <li *ngFor="#person of people">
  157. * {{person.name}}
  158. * </li>
  159. * </ul>
  160. * </div>
  161. * `,
  162. * directives: [NgFor]
  163. * })
  164. * export class App {
  165. * people: Array<Object>;
  166. * constructor(jsonp:Jsonp) {
  167. * jsonp.request('people.json').subscribe(res => {
  168. * this.people = res.json();
  169. * })
  170. * }
  171. * }
  172. * ```
  173. *
  174. * The primary public API included in `JSONP_PROVIDERS` is the {@link Jsonp} class.
  175. * However, other providers required by `Jsonp` are included,
  176. * which may be beneficial to override in certain cases.
  177. *
  178. * The providers included in `JSONP_PROVIDERS` include:
  179. * * {@link Jsonp}
  180. * * {@link JSONPBackend}
  181. * * `BrowserJsonp` - Private factory
  182. * * {@link RequestOptions} - Bound to {@link BaseRequestOptions} class
  183. * * {@link ResponseOptions} - Bound to {@link BaseResponseOptions} class
  184. *
  185. * There may be cases where it makes sense to extend the base request options,
  186. * such as to add a search string to be appended to all URLs.
  187. * To accomplish this, a new provider for {@link RequestOptions} should
  188. * be added in the same injector as `JSONP_PROVIDERS`.
  189. *
  190. * ### Example ([live demo](http://plnkr.co/edit/TFug7x?p=preview))
  191. *
  192. * ```
  193. * import {provide} from 'angular2/core';
  194. * import {bootstrap} from 'angular2/platform/browser';
  195. * import {JSONP_PROVIDERS, BaseRequestOptions, RequestOptions} from 'angular2/http';
  196. *
  197. * class MyOptions extends BaseRequestOptions {
  198. * search: string = 'coreTeam=true';
  199. * }
  200. *
  201. * bootstrap(App, [JSONP_PROVIDERS, provide(RequestOptions, {useClass: MyOptions})])
  202. * .catch(err => console.error(err));
  203. * ```
  204. *
  205. * Likewise, to use a mock backend for unit tests, the {@link JSONPBackend}
  206. * provider should be bound to {@link MockBackend}.
  207. *
  208. * ### Example ([live demo](http://plnkr.co/edit/HDqZWL?p=preview))
  209. *
  210. * ```
  211. * import {provide, Injector} from 'angular2/core';
  212. * import {JSONP_PROVIDERS, Jsonp, Response, JSONPBackend} from 'angular2/http';
  213. * import {MockBackend} from 'angular2/http/testing';
  214. *
  215. * var people = [{name: 'Jeff'}, {name: 'Tobias'}];
  216. * var injector = Injector.resolveAndCreate([
  217. * JSONP_PROVIDERS,
  218. * MockBackend,
  219. * provide(JSONPBackend, {useExisting: MockBackend})
  220. * ]);
  221. * var jsonp = injector.get(Jsonp);
  222. * var backend = injector.get(MockBackend);
  223. *
  224. * // Listen for any new requests
  225. * backend.connections.observer({
  226. * next: connection => {
  227. * var response = new Response({body: people});
  228. * setTimeout(() => {
  229. * // Send a response to the request
  230. * connection.mockRespond(response);
  231. * });
  232. * });
  233. * jsonp.get('people.json').observer({
  234. * next: res => {
  235. * // Response came from mock backend
  236. * console.log('first person', res.json()[0].name);
  237. * }
  238. * });
  239. * ```
  240. */
  241. export declare const JSONP_PROVIDERS: any[];
  242. /**
  243. * See {@link JSONP_PROVIDERS} instead.
  244. *
  245. * @deprecated
  246. */
  247. export declare const JSON_BINDINGS: any[];