Backend & APIs
Configure and integrate backend services and APIs.
The project uses Expo API Router to create tRPC server endpoints.
tRPC ensures type-safe API communication between the frontend and backend, allowing a unified codebase that supports both the mobile app and web app, which simplifies development and maintains consistent data handling.
Project Structure
The project is organized to clearly separate frontend and backend code, with a shared codebase for common logic.
packages/api/
: Contains all backend-related files, including tRPC routers and context setup.packages/db
: Contains the db setup, including the migration configuration.
Defining new API route
Create and configure a new API route using tRPC. This example shows how to define a route that fetches user preferences.
Calling the Query in React Components
Fetch and display data from the API in React components. This example demonstrates how to use the trpc hook to retrieve user preferences and handle loading and data states.
Exposing the Query in OpenAPI Documentation
Add metadata to your API route to make it visible in OpenAPI documentation. This example shows how to document an endpoint that returns user preferences, including the method, path, and summary.
OpenAPI
Provide both .input()
and .output()
zod schemas to make the route visible in the OpenAPI documentation.
Without these, the route will not appear in the OpenAPI documentation.
You can view the new route in the OpenAPI documentation at http://localhost:8081/api/docs