API Reference

API Overview

Comprehensive API documentation for Flutter app and ESP32 communication

API Architecture

Gridova uses a hybrid architecture with REST API for standard operations and WebSocket for real-time sensor data streaming.
REST API
HTTP endpoints for CRUD operations, authentication, and device control
WebSocket API
Real-time bidirectional communication for sensor data streaming

Base URLs

Backend API

// Production
https://api.gridova.com

// Development
http://localhost:8000

// Staging
https://staging-api.gridova.com

ESP32 Device API

// Device IP (configured per installation)
http://192.168.1.100

// Example endpoints
http://192.168.1.100/api/sensor
http://192.168.1.100/api/relay

Each ESP32 device has its own IP address on the local network.

WebSocket URL

// Production
wss://api.gridova.com/ws

// Development
ws://localhost:8000/ws

Authentication

Gridova uses JWT (JSON Web Tokens) for authentication.

Login

Requestjson
POST /api/auth/login

{
  "email": "admin@gridova.com",
  "password": "admin123"
}
Response (200 OK)json
{
  "success": true,
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "user": {
    "id": 1,
    "email": "admin@gridova.com",
    "name": "Admin User",
    "role": "admin"
  }
}

Using the Token

// Include token in Authorization header
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

All protected endpoints require this header.

API Endpoints Overview

Backend API Endpoints

EndpointMethodDescription
/api/auth/loginPOSTAuthenticate user
/api/roomsGETList all rooms
/api/rooms/:idGETGet room details
/api/tenantsGETList all tenants
/api/transactionsGETList transactions
/api/reports/energyGETEnergy consumption report

View complete REST API documentation →

ESP32 Device Endpoints

EndpointMethodDescription
/api/sensorGETGet current sensor readings
/api/sensor/historyGETGet historical data
/api/relayGETGet relay status
/api/relay/controlPOSTControl relay (ON/OFF)
/api/statusGETDevice health check

Response Format

All API responses follow a consistent JSON format:

Success Response

{
  "success": true,
  "data": {
    // Response data
  },
  "message": "Operation completed successfully"
}

Error Response

{
  "success": false,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Invalid input data",
    "details": {
      "field": "email",
      "issue": "Invalid email format"
    }
  }
}

HTTP Status Codes

CodeStatusDescription
200OKRequest successful
201CreatedResource created successfully
400Bad RequestInvalid request data
401UnauthorizedAuthentication required
403ForbiddenInsufficient permissions
404Not FoundResource not found
500Server ErrorInternal server error

Rate Limiting

API requests are rate limited to ensure fair usage:

  • Backend API: 100 requests per minute per IP
  • ESP32 Device: 10 requests per second
  • WebSocket: 1 connection per device

Rate Limit Exceeded

When rate limit is exceeded, the API returns status code 429 (Too Many Requests). Implement exponential backoff in your client applications.