Kundli API in a React Native app
Show a birth chart and current dasha in React Native, with the API key safely on your backend.
This guide builds a kundli screen in React Native (Expo or bare): the user's planets with sign, degree and house, plus their current Vimshottari dasha. It takes two LifeAstroAPI calls, 20 credits per new user.
1. Why a backend is required
A React Native bundle can be unpacked, so an API key inside the app is public. Put a tiny backend between the app and LifeAstroAPI. Below is a complete one in Express using the official Node SDK (npm install lifeastroapi express).
// server.js — your backend (Node 18+). The API key stays here.
import express from 'express';
import { LifeAstro } from 'lifeastroapi';
const app = express();
const astro = new LifeAstro({ apiKey: process.env.LIFEASTRO_API_KEY });
// Birth chart + current dasha in one round trip for the app.
app.get('/kundli', async (req, res) => {
const { date, time, tz, lat, lon } = req.query;
const birth = { date, time, tz, lat: Number(lat), lon: Number(lon) };
try {
const [chart, dasha] = await Promise.all([
astro.chart.planets(birth), // 10 credits
astro.dasha.vimshottariCurrent(birth), // 10 credits
]);
res.json({ planets: chart.planets, maha: dasha.maha, antar: dasha.antar });
} catch (e) {
res.status(502).json({ error: String(e) });
}
});
// Place search for the birth-place picker (returns lat, lon, IANA timezone).
app.get('/places', async (req, res) => {
res.json(await astro.geo.search({ q: String(req.query.q ?? ''), limit: 8 }));
});
app.listen(3000);2. What the API returns
planets lists the nine grahas, Sun to Ketu. Each entry looks like this (Sun for a sample birth on 15 Jan 1990, 10:30, Mumbai):
{
"id": "sun",
"name": "Sun",
"sidereal_lon": 271.0633,
"sign_index": 9,
"deg_in_sign": 1.0633,
"dms_in_sign": "01°03'47\"",
"house": 12,
"nakshatra_idx": 20,
"pada": 2,
"nak_lord": "Sun",
"speed": 1.0183,
"is_retro": false
}sign_index is 0 for Mesha through 11 for Meena, house is counted from the lagna, and is_retro marks retrograde motion. The current-dasha call returns maha, antar and deeper levels, each with lord, start_local and end_local.
3. The React Native screen
// KundliScreen.tsx — React Native. Talks only to YOUR backend.
import { useEffect, useState } from 'react';
import { FlatList, Text, View } from 'react-native';
const SIGNS = ['Mesha', 'Vrishabha', 'Mithuna', 'Karka', 'Simha', 'Kanya',
'Tula', 'Vrishchika', 'Dhanu', 'Makara', 'Kumbha', 'Meena'];
type Planet = { id: string; name: string; sign_index: number;
dms_in_sign: string; house: number; pada: number; is_retro: boolean };
export function KundliScreen() {
const [planets, setPlanets] = useState<Planet[]>([]);
const [dasha, setDasha] = useState('');
useEffect(() => {
const q = new URLSearchParams({ date: '1990-01-15', time: '10:30',
tz: 'Asia/Kolkata', lat: '19.076', lon: '72.8777' });
fetch('https://your-backend.example.com/kundli?' + q)
.then((r) => r.json())
.then((d) => {
setPlanets(d.planets);
setDasha(d.maha.lord + ' / ' + d.antar.lord + ' until ' + d.antar.end_local.slice(0, 10));
});
}, []);
return (
<View style={{ padding: 16 }}>
<Text style={{ fontSize: 16, marginBottom: 8 }}>Current dasha: {dasha}</Text>
<FlatList
data={planets}
keyExtractor={(p) => p.id}
renderItem={({ item: p }) => (
<Text>
{p.name}{p.is_retro ? ' (R)' : ''} — {SIGNS[p.sign_index]} {p.dms_in_sign}, house {p.house}
</Text>
)}
/>
</View>
);
}4. Birth-place picker
Users type a city; call your /places route (which wraps /v1/geo/search) and store the chosen latitude, longitude and timezone with the birth date and time. Those five values are all every chart endpoint needs.
5. Make it fast and cheap
- Save the chart in your database the first time; it never changes for the same birth data.
- Recompute only the current dasha, and only when its
end_localhas passed. - For a full kundli add
/v1/chart/ascendant,/v1/chart/divisional/D9and/v1/chart/ashtakvarga; see the birth chart guide. - Need a shareable PDF? The report endpoints return a finished kundli PDF.