API Integration
This document explains how the Rhesis frontend application integrates with the Rhesis backend API.
API Client Architecture
The Rhesis frontend communicates exclusively with the Rhesis backend API for all data operations and authentication. The frontend uses a centralized API client to handle all requests to the Rhesis backend. This client is built with:
- Type safety for request and response data
- Automatic authentication handling with Auth0 tokens
- Error handling and retries
- Request caching where appropriate
- Consistent error formatting
Rhesis Backend API
The Rhesis backend API serves as the intermediary between the frontend and various services:
- Authentication: The backend handles Auth0 authentication and token management
- Data Storage: The backend manages all data persistence and retrieval
- Business Logic: Complex business logic is implemented in the backend
- External Service Integration: The backend integrates with any third-party services
All frontend requests are routed through the Rhesis backend API, which provides a unified interface for the frontend application.
API Client Implementation
The API client is implemented in src/utils/api-client/:
Base Client
The base client is implemented in src/utils/api-client/client.ts and handles communication with the Rhesis backend API:
Endpoint Definitions
API endpoints are defined in separate files for each resource, all targeting the Rhesis backend API:
Type Definitions
API types are defined to match the Rhesis backend API response structures:
Using the API Client
In Server Components
In server components, you can use the API client to communicate with the Rhesis backend:
In Client Components
In client components, you can use the API client with React hooks to communicate with the Rhesis backend:
Server Actions
For form submissions and mutations, you can use server actions that communicate with the Rhesis backend API:
API Configuration
The Rhesis backend API URL is configured in environment variables:
For local development, you might point to a local instance of the Rhesis backend:
Error Handling
The API client includes centralized error handling for Rhesis backend API errors:
API Documentation
For detailed Rhesis backend API endpoint configuration, refer to the Endpoint Configuration document.