Base URL and Versioning
The Water Quality Backend API is built with FastAPI and provides RESTful endpoints for managing water quality monitoring systems./v1/). All endpoints are accessed directly from the base URL.
Request and Response Format
All API requests and responses use JSON format withContent-Type: application/json.
Request Headers
Response Structure
Successful responses typically follow this structure:Common HTTP Status Codes
The API uses standard HTTP status codes to indicate the success or failure of requests:| Status Code | Description |
|---|---|
200 | Success - Request completed successfully |
201 | Created - Resource created successfully |
400 | Bad Request - Invalid request parameters or data |
401 | Unauthorized - Missing or invalid authentication token |
403 | Forbidden - Insufficient permissions |
404 | Not Found - Resource not found |
500 | Internal Server Error - Server encountered an error |
502 | Bad Gateway - Error communicating with external services |
504 | Gateway Timeout - Request timeout |
Error Response Format
When an error occurs, the API returns a consistent error response:Example Error Responses
CORS Configuration
The API is configured with permissive CORS settings to allow cross-origin requests from any domain. CORS Settings (from~/workspace/source/app/__init__.py:19-26):
The
Content-Disposition header is exposed to support file downloads (e.g., PDF reports).Rate Limiting
Currently, the API does not implement rate limiting at the application level. However, you should implement rate limiting at the infrastructure level (reverse proxy, API gateway) for production deployments.WebSocket Support for Real-Time Data
The API provides Socket.IO endpoints for real-time water quality monitoring data.WebSocket Namespaces
The API implements two Socket.IO namespaces:1. /receive/ - Meter Data Ingestion
Used by IoT meters to send real-time water quality measurements.
Authentication: Requires a JWT token for meter connections
Connection Example:
connect- Connection establishedmessage- Send meter readingsdisconnect- Connection closederror- Error occurred
2. /subscribe/ - Real-Time Data Subscription
Used by client applications to receive real-time updates from meters.
Authentication: Requires a user JWT token
Connection Example:
connect- Subscribed to meter updatesmessage- Receive meter readingsdisconnect- Subscription endederror- Error occurred
WebSocket connections require valid workspace access. Users must have
VISITOR, MANAGER, or ADMINISTRATOR roles, or the workspace must be public.WebSocket Authentication
WebSocket connections support two authentication methods:- Header-based:
HTTP_ACCESS_TOKENheader - Query parameter:
?access_token=<token>
~/workspace/source/app/share/socketio/__init__.py:46-71 for implementation details.
API Endpoints Overview
The API is organized into the following feature modules:| Module | Base Path | Description |
|---|---|---|
| Authentication | /auth | User registration, login, password reset, OAuth |
| Workspaces | /workspaces | Workspace management and sharing |
| Meters | /meters | Water quality meter configuration |
| Alerts | /alerts | Alert configuration and notifications |
| Users | /users | User profile management |
| Monitoring | /monitoring | Real-time monitoring data |
| Analysis | /analysis | Data analysis, reports, and predictions |
Firebase Integration
The API uses Firebase for:- User authentication (Firebase Auth)
- Real-time database operations
- Password reset verification codes
Firebase initialization can be skipped in development by setting
SKIP_FIREBASE_INIT=true.Getting Started
Obtain an API Token
Register an account and authenticate to receive a JWT token. See the Authentication guide.
Next Steps
- Learn about API Authentication methods
- Explore endpoint documentation for each module
- Set up WebSocket connections for real-time data