Skip to main content
The Despia native bridge gives your web app direct access to Apple HealthKit, covering quantity types, category types (including sleep), workouts, and characteristics. Data is returned as JSON via the despia() call.
HealthKit is iOS only. Always gate calls behind an isDespiaIOS check so the feature degrades gracefully in a browser or on Android.

Installation


How it works

Pass a readhealthkit:// URL with an identifier and optional days parameter. Despia requests permission, fetches the data, and returns it via healthkitResponse.

Read

Quantity types

Use any valid HKQuantityTypeIdentifier to read numeric health metrics such as steps, heart rate, distance, or body mass.
For a full list of supported identifiers, see Apple’s HKQuantityTypeIdentifier documentation.

Sleep data

Sleep analysis uses HKCategoryTypeIdentifierSleepAnalysis. Each record includes a label with the sleep stage (inBed, awake, core, deep, rem, or asleep) alongside startDate and endDate.

Workouts

Use HKWorkoutTypeIdentifier to fetch workout sessions. Each record includes activityType (e.g. running, yoga, hiit), duration in seconds, calories, and distance in meters.

Characteristics

Characteristics such as date of birth, biological sex, and blood type are static values. They are returned as a plain string rather than an array.
Supported identifiers: HKCharacteristicTypeIdentifierDateOfBirth, HKCharacteristicTypeIdentifierBiologicalSex, HKCharacteristicTypeIdentifierBloodType, HKCharacteristicTypeIdentifierFitzpatrickSkinType.

Write

Use writehealthkit:// to save a numeric value to HealthKit. The format is writehealthkit://IdentifierString//Value. Writing adds to existing data rather than replacing it.

Realtime updates

The observer system fires a webhook POST to your server whenever HealthKit data changes. Pass a comma-separated list of identifiers, a delivery frequency, and your server URL.

Parameters

Webhook payload

Your server receives a POST with Content-Type: application/json on every update. The data object contains one key per observed type, each holding an array of the most recent records (last 1 day).

Payload fields

Each record in data follows the same shape as a standard read response for that type. Quantity types include date, value, and unit. Category types include startDate, endDate, value, and label. Workout records include date, activityType, duration, calories, and distance.

Stopping observers

Pass all to stop every active observer or a comma-separated list for specific types. Awaiting with ["observingHealthKit"] returns the updated active types after the call resolves.

Resources

NPM Package

despia-native