Skip to main content

fromFetch

Types

function fromFetch(
requestInfo: RequestInfo,
requestInit?: RequestInit,
): IObservable<IFromFetchObservableNotifications>

Definition

Creates an Observable performing an HTTP request using the fetch api.

For details, you may see fromPromiseFactory.

Shortcuts

If you prefer to receive json, text, an array buffer, a blob or a stream, you may use the following functions:

Examples

Simple http request

const subscribe = fromFetch('https://some-url.site');

subscribe((notification) => {
console.log(notification.name, ':', notification.value);
});

Output:

if fulfilled

next: Response
complete

if rejected

error: Error

Simple http request with JSON response

const subscribe = fromFetchJSON('https://some-url.site');

subscribe((notification) => {
console.log(notification.name, ':', notification.value);
});

Output:

if fulfilled

next: { ...json content }
complete

if rejected

error: Error