Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Contributing / Development

Instructions for local development

API

The following functions are exported from the @openmrs/esm-api module:

openmrsFetch(url, init):

...

Promise

The openmrsFetch function is a wrapper around the browser's built-in fetch function, with extra handling for OpenMRS-specific API behaviors, such as request headers, authentication, authorization, and the API urls.

...

An Observable that produces zero or more values (as described above). The values produced will be a user object (if includeAuthStatus is set to false) or an object with a session and authenticated property (if includeAuthStatus is set to true).

Example

import { getCurrentUser } from '@openmrs/esm-api'

const subscription = getCurrentUser().subscribe(
  user => console.log(user)
)
subscription.unsubscribe()

getCurrentUser({includeAuthStatus: true}).subscribe(
  data => console.log(data.authenticated)
)

...

Otherwise your code will continue getting updates to the user object even after the UI component is gone from the screen. This is a memory leak and source of bugs.

refetchCurrentUser(): Observable

The refetchCurrentUser function causes a network request to redownload the user. All subscribers to the current user will be notified of the new users once the new version of the user object is downloaded.

Arguments

None

Return value

An observable exactly the same as if you had called getCurrentUser().

Example

import { refetchCurrentUser } from '@openmrs/esm-api'

refetchCurrentUser()