Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fetch.d.ts 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { Observable } from '../../Observable';
  2. /**
  3. * Uses [the Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) to
  4. * make an HTTP request.
  5. *
  6. * **WARNING** Parts of the fetch API are still experimental. `AbortController` is
  7. * required for this implementation to work and use cancellation appropriately.
  8. *
  9. * Will automatically set up an internal [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController)
  10. * in order to teardown the internal `fetch` when the subscription tears down.
  11. *
  12. * If a `signal` is provided via the `init` argument, it will behave like it usually does with
  13. * `fetch`. If the provided `signal` aborts, the error that `fetch` normally rejects with
  14. * in that scenario will be emitted as an error from the observable.
  15. *
  16. * ### Basic Use
  17. *
  18. * ```ts
  19. * import { of } from 'rxjs';
  20. * import { fromFetch } from 'rxjs/fetch';
  21. * import { switchMap, catchError } from 'rxjs/operators';
  22. *
  23. * const data$ = fromFetch('https://api.github.com/users?per_page=5').pipe(
  24. * switchMap(response => {
  25. * if (response.ok) {
  26. * // OK return data
  27. * return response.json();
  28. * } else {
  29. * // Server is returning a status requiring the client to try something else.
  30. * return of({ error: true, message: `Error ${response.status}` });
  31. * }
  32. * }),
  33. * catchError(err => {
  34. * // Network or other error, handle appropriately
  35. * console.error(err);
  36. * return of({ error: true, message: err.message })
  37. * })
  38. * );
  39. *
  40. * data$.subscribe({
  41. * next: result => console.log(result),
  42. * complete: () => console.log('done')
  43. * })
  44. * ```
  45. *
  46. * @param input The resource you would like to fetch. Can be a url or a request object.
  47. * @param init A configuration object for the fetch.
  48. * [See MDN for more details](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
  49. * @returns An Observable, that when subscribed to performs an HTTP request using the native `fetch`
  50. * function. The {@link Subscription} is tied to an `AbortController` for the the fetch.
  51. */
  52. export declare function fromFetch(input: string | Request, init?: RequestInit): Observable<Response>;