expo-api-routes
API routes in Expo Router for server-side logic, secrets, and third-party integrations on EAS Hosting.
- Create routes with
+api.tssuffix in theappdirectory; export named functions for HTTP methods (GET, POST, PUT, DELETE) - Handle query parameters, headers, JSON bodies, and dynamic route segments; add CORS headers for web clients
- Access server-side secrets via
process.env; set variables locally in.envor viaeas env:createfor production - Deploy to EAS Hosting (Cloudflare Workers) with
eas deploy; use cloud databases (Turso, Supabase, PlanetScale) since filesystem and Node.js modules are unavailable - Test locally with
npx expo serveand curl; call routes from client with standard fetch to relative paths like/api/hello
When to Use API Routes
Use API routes when you need:
- Server-side secrets — API keys, database credentials, or tokens that must never reach the client
- Database operations — Direct database queries that shouldn't be exposed
- Third-party API proxies — Hide API keys when calling external services (OpenAI, Stripe, etc.)
- Server-side validation — Validate data before database writes
- Webhook endpoints — Receive callbacks from services like Stripe or GitHub
- Rate limiting — Control access at the server level
- Heavy computation — Offload processing that would be slow on mobile
When NOT to Use API Routes
Avoid API routes when:
- Data is already public — Use direct fetch to public APIs instead
- No secrets required — Static data or client-safe operations
- Real-time updates needed — Use WebSockets or services like Supabase Realtime
More from expo/skills
building-native-ui
Complete guide for building beautiful apps with Expo Router. Covers fundamentals, styling, components, navigation, animations, patterns, and native tabs.
39.0Knative-data-fetching
Use when implementing or debugging ANY network request, API call, or data fetching. Covers fetch API, React Query, SWR, error handling, caching, offline support, and Expo Router data loaders (`useLoaderData`).
30.9Kexpo-tailwind-setup
Set up Tailwind CSS v4 in Expo with react-native-css and NativeWind v5 for universal styling
27.1Kupgrading-expo
Guidelines for upgrading Expo SDK versions and fixing dependency issues
26.9Kexpo-cicd-workflows
Helps understand and write EAS workflow YAML files for Expo projects. Use this skill when the user asks about CI/CD or workflows in an Expo or EAS context, mentions .eas/workflows/, or wants help with EAS build pipelines or deployment automation.
25.6Kexpo-deployment
Deploying Expo apps to iOS App Store, Android Play Store, web hosting, and API routes
25.2K