openmrs-esm-core

O3 Framework / openmrsObservableFetch

Function: openmrsObservableFetch()

openmrsObservableFetch<T>(url, fetchInit): Observable<FetchResponse<T>>

Defined in: packages/framework/esm-api/src/openmrs-fetch.ts:279

The openmrsObservableFetch function is a wrapper around openmrsFetch that returns an Observable instead of a promise. It exists in case using an Observable is preferred or more convenient than a promise.

Type Parameters

T

T

Parameters

url

string

See [[openmrsFetch]]

fetchInit

FetchConfig = {}

See [[openmrsFetch]]

Returns

Observable<FetchResponse<T>>

An Observable that produces exactly one Response object. The response object is exactly the same as for [[openmrsFetch]].

Example

import { openmrsObservableFetch } from '@openmrs/esm-api'
const subscription = openmrsObservableFetch(`${restBaseUrl}/session').subscribe(
  response => console.log(response.data),
  err => {throw err},
  () => console.log('finished')
)
subscription.unsubscribe()

Cancellation

To cancel the network request, simply call subscription.unsubscribe();