expo-api-routes
What it does
This tool lets you create 'API routes' in your Expo app. API routes are like small programs that run on a server to handle tasks that can't or shouldn't be done directly on the phone, like storing secrets or talking to other services.
When to use it
- βWhen you need to store secret information (passwords, API keys) that cannot go to the phone.
- βTo perform direct database operations without exposing the details.
- βTo communicate with other online services (like OpenAI or Stripe) securely.
Skill link
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/expo-api-routes/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βCreate an API route to fetch user data and protect it with a secret key.β
5 new skills a week. 1 minute to read.
How it works
You create special files named `+api.ts` inside the `app` folder. Each file can respond to different types of requests (like viewing data, creating data, etc.) using functions like `GET`, `POST`, `PUT`, and `DELETE`.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
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
- Simple CRUD β Consider Firebase, Supabase, or Convex for managed backends
- File uploads β Use direct-to-storage uploads (S3 presigned URLs, Cloudflare R2)
- Authentication only β Use Clerk, Auth0, or Firebase Auth instead
File Structure
API routes live in the app directory with +api.ts suffix:
app/
api/
hello+api.ts β GET /api/hello
users+api.ts β /api/users
users/[id]+api.ts β /api/users/:id
(tabs)/
index.tsx
Basic API Route
// app/api/hello+api.ts
export function GET(request: Request) {
return Response.json({ message: "Hello from Expo!" });
}
HTTP Methods
Export named functions for each HTTP method:
// app/api/items+api.ts
export function GET(request: Request) {
return Response.json({ items: [] });
}
export async function POST(request: Request) {
const body = await request.json();
return Response.json({ created: body }, { status: 201 });
}
export async function PUT(request: Request) {
const body = await request.json();
return Response.json({ updated: body });
}
export async function DELETE(request: Request) {
return new Response(null, { status: 204 });
}
Dynamic Routes
// app/api/users/[id]+api.ts
export function GET(request: Request, { id }: { id: string }) {
return Response.json({ userId: id });
}
Request Handling
Query Parameters
export function GET(request: Request) {
const url = new URL(request.url);
const page = url.searchParams.get("page") ?? "1";
const limit = url.searchParams.get("limit") ?? "10";
return Response.json({ page, limit });
}
Headers
export function GET(request: Request) {
const auth = request.headers.get("Authorization");
if (!auth) {
return Response.json({ error: "Unauthorized" }, { status: 401 });
}
return Response.json({ authenticated: true });
}
JSON Body
export async function POST(request: Request) {
const { email, password } = await request.json();
if (!email || !password) {
return Response.json({ error: "Missing fields" }, { status: 400 });
}
return Response.json({ success: true });
}
Environment Variables
Use process.env for server-side secrets:
// app/api/ai+api.ts
export async function POST(request: Request) {
const { prompt } = await request.json();
const response = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
},
body: JSON.stringify({
model: "gpt-4",
messages: [{ role: "user", content: prompt }],
}),
});
const data = await response.json();
return Response.json(data);
}
Set environment variables:
- Local: Create
.envfile (never commit) - EAS Hosting: Use
eas env:createor Expo dashboard
CORS Headers
Add CORS for web clients:
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
};
export function OPTIONS() {
return new Response(null, { headers: corsHeaders });
}
export function GET() {
return Response.json({ data: "value" }, { headers: corsHeaders });
}
Error Handling
export async function POST(request: Request) {
try {
const body = await request.json();
// Process...
return Response.json({ success: true });
} catch (error) {
console.error("API error:", error);
β¦
FAQ
What are 'API routes'?
They are like 'doors' in your app that, instead of showing a screen, run code on a server to perform specific tasks, like fetching or saving information securely.
Where do I put these `+api.ts` files?
They go inside the `app` folder of your project, usually in a subfolder named `api`.
Can I use this for everything?
No. If the data is public, or you need real-time updates, or it's something simple like authentication, there are better tools. This is for tasks that need a 'brain' on the server.
Details
Original description by the author
Guidelines for creating API routes in Expo Router with EAS Hosting
Popularity
- GitHub stars
- 48k
- Ranking position
- #4569
- License
- MIT
- Updated
- 10/15/2026
Comments
- β¦
More skills from this repository
00-andruia-consultant
48kHelps your agent start or improve AI projects. It analyzes code, suggests tools, and creates action plans in Spanish.
007
48kLets your agent perform security audits and threat modeling. It's useful for protecting projects against attacks and vulnerabilities.
10-andruia-skill-smith
48kHelps your agent create or improve AI tools. It defines how tools work, writes documentation, and validates the structure.
20-andruia-niche-intelligence
48kLets your agent create a summary about a specific industry. It's useful for understanding the context, rules, usage patterns, and risks of a project, using reliable sources.
Similar skills
api-connector-builder
280kHas your agent build new API connections following the existing pattern. Use when you need to add one more integration without creating a new way of doing things.
api-design
280kHelps your agent design REST APIs following best practices. It's useful for defining how APIs communicate, how errors are shown, and how to organize data.
backend-patterns
280kHelps your agent with server-side architecture patterns and database optimization. It's useful for building or reviewing code that runs on the server.