Skip to main content

Resource Routes

Resource routes return non-HTML responses like JSON, PDF, images, or any other data format. They’re useful for creating APIs, webhooks, and downloadable files.

Basic Resource Route

A resource route is just a loader/action without a default component export:
filename=app/routes/api.products.tsx

JSON API

Create RESTful JSON endpoints:
filename=app/routes/api.users.$id.tsx

File Downloads

Serve downloadable files:
filename=app/routes/reports.$id.pdf.tsx

CSV Export

filename=app/routes/export.users.csv.tsx

Image Generation

filename=app/routes/og.$title.png.tsx

RSS Feed

filename=app/routes/blog.rss.tsx

Webhooks

Handle incoming webhooks:
filename=app/routes/webhooks.stripe.tsx

XML Sitemap

filename=app/routes/sitemap[.]xml.tsx

robots.txt

filename=app/routes/robots[.]txt.tsx

Health Check

filename=app/routes/healthz.tsx

Proxying Requests

filename=app/routes/proxy.tsx

Server-Sent Events

filename=app/routes/events.tsx

Binary Data

filename=app/routes/qr.$data.png.tsx

GraphQL API

filename=app/routes/api.graphql.tsx

Authentication Check

filename=app/routes/api.auth.check.tsx

Best Practices

Set Appropriate Headers

Handle Errors

Use HTTP Status Codes

Validate Input