What problem does it solve?
expo-api-routes helps you design API endpoints in an Expo Router app so sensitive logic and secrets stay on the server, while client requests remain simple and safe.
Core Features & Use Cases
- Use API routes for server-side secrets: Keep keys and credentials (e.g., OpenAI/Stripe) out of the client while still enabling the needed functionality.
- Implement robust REST endpoints: Create GET/POST/PUT/DELETE handlers with dynamic route segments like users/[id] for structured resources.
- Handle production constraints on EAS Hosting: Prepare for Cloudflare Workers limitations by using Web APIs and edge-friendly database options.
- Add web-ready CORS and consistent error handling: Support browser clients and return appropriate status codes for validation and failures.
- Use environment variables correctly: Store secrets with process.env and configure them for local development and EAS/production.
Quick Start
Create a new file in your Expo Router app under app/api with the +api.ts suffix (for example, app/api/hello+api.ts) and implement the required named HTTP method exports to return Response.json from your server code.