Remix doesn't just serve pages — its loader/action pattern IS your API layer.
Loaders Are GET Endpoints
Every Remix route with a loader function is automatically a JSON API endpoint:
// app/routes/api.users.jsx
export async function loader({ request }) {
const url = new URL(request.url)
const search = url.searchParams.get('q')
const users = await db.user.findMany({
where: { name: { contains: search } }
})
return json(users)
}
Hit /api/users?q=john with Accept: application/json and you get pure JSON back. No extra setup.
Actions Are POST/PUT/DELETE Endpoints
// app/routes/api.posts.jsx
export async function action({ request }) {
const formData = await request.formData()
switch (request.method) {
case 'POST':
return json(await db.post.create({
data: { title: formData.get('title') }
}))
case 'DELETE':
return json(await db.post.delete({
where: { id: formData.get('id') }
}))
}
}
Resource Routes — Pure API
Resource routes (routes without a default export) are dedicated API endpoints:
// app/routes/api.health.jsx
export function loader() {
return json({ status: 'ok', timestamp: Date.now() })
}
// No default export = pure API, no HTML
The Fetch-First Architecture
Remix uses the Web Fetch API natively. Request, Response, Headers — all standard:
export async function loader({ request }) {
const cookie = request.headers.get('Cookie')
const session = await getSession(cookie)
if (!session.has('userId')) {
throw new Response('Unauthorized', { status: 401 })
}
return json({ user: session.get('userId') })
}
Real-World Use Case
A team building a mobile app needed a backend. Instead of spinning up Express, they built their entire API as Remix resource routes. Same codebase serves the web app AND the mobile API. One deployment. Zero duplication.
When your framework IS your API server, you build faster.
Build Smarter Data Pipelines
Need to scrape websites, extract APIs, or automate data collection? Check out my ready-to-use scrapers on Apify — no coding required.
Custom scraping solution? Email me at spinov001@gmail.com — fast turnaround, fair prices.
Top comments (0)