@opengolfapi/expo
v0.1.0
Published
OpenGolf mobile SDK for Expo / React Native — the FREE golf-data surface (16k+ courses, tees, holes, hazards facts, weather, Sign in with OpenGolf, contribution) with offline caching, near-me, and typed models. No gated capability.
Maintainers
Readme
@opengolfapi/expo
The OpenGolf mobile SDK for Expo / React Native. The free golf-data surface — 16k+ courses with holes, scorecard, hazard facts, location search, Sign in with OpenGolf, and free contribution — with offline course bundles, courses-near-me, and typed models. Drop-in, fetch-based, no Node deps.
This SDK is the free surface only. Advanced geometry, the OpenGolf Rating, wallet/rewards, and booking are the enterprise layer and are not part of this package.
Install
npx expo install @opengolfapi/expo
# offline bundles use AsyncStorage:
npx expo install @react-native-async-storage/async-storageQuickstart
import { OpenGolfMobile } from '@opengolfapi/expo';
import AsyncStorage from '@react-native-async-storage/async-storage';
const og = new OpenGolfMobile({ storage: AsyncStorage }); // no key needed for reads
// Courses near the golfer
const { courses } = await og.coursesNearMe(56.348, -2.814, 15); // St Andrews area, 15 mi
// Full course (facts + holes + scorecard)
const course = await og.course(courses[0].id);
// Play offline: download before the round, then `course()` works with no signal
await og.downloadCourse(courses[0].id);Sign in with OpenGolf (OIDC)
import * as AuthSession from 'expo-auth-session';
const redirectUri = AuthSession.makeRedirectUri();
const url = og.signInUrl({ clientId: 'your.app', redirectUri, scope: 'openid profile' });
// open `url` in an AuthSession; on return you get `code`:
const tokens = await og.exchangeCode({ code, clientId: 'your.app', redirectUri });
// then reads on the golfer's OWN data:
const chain = new OpenGolfMobile({ apiKey: tokens.access_token }).myChain();Contribute from the app (free)
const keyed = new OpenGolfMobile({ apiKey: FREE_KEY });
await keyed.submitCorrection({ course_id, field: 'phone', value: '+44 1334 466718' });
await keyed.submitRound(course_id, gpsTrack); // breadcrumbs feed the open mapAPI (free surface)
| Method | What |
|---|---|
| searchCourses(q) | name search (global) |
| coursesNearMe(lat, lng, radiusMi?) | location search |
| course(id) | facts + holes + scorecard + hazard facts (offline-first) |
| holes(id) | per-hole par / yardage / stroke index |
| coursesInState(code) | every course in a US state |
| downloadCourse(id) / isDownloaded / removeDownload | offline bundles |
| submitCorrection / submitRound | free contribution (needs a free key) |
| signInUrl / exchangeCode / myChain | Sign in with OpenGolf + own data |
Reads are cache-first (24h default) and fall back to the last persisted copy when offline.
MIT · built on the open OpenGolfAPI.
