A RESTful API built with Express.js that provides a simplified interface for interacting with Supabase databases. This API abstracts away the complexity of direct Supabase client usage and provides a consistent interface for common database operations.
- Table management (create, drop, check existence)
- CRUD operations (create, read, update, delete)
- Swagger documentation
- Error handling middleware
- TypeScript support
- Unit tests
- Node.js (v14 or higher)
- npm or yarn
- Supabase account and project
- Environment variables (see Configuration section)
- Clone the repository:
git clone <repository-url>
cd supabase-api- Install dependencies:
npm install- Configure environment variables:
cp .env.example .envEdit the .env file with your Supabase credentials.
The following environment variables are required:
SUPABASE_URL=your_supabase_project_url
SUPABASE_KEY=your_supabase_anon_key
PORT=3000
API_PREFIX=/api/v1POST /api/v1/supabase/tablesRequest body:
{
"tableName": "users",
"schema": {
"id": "uuid primary key",
"name": "text",
"email": "text unique",
"created_at": "timestamp with time zone default now()"
}
}DELETE /api/v1/supabase/tables/:tableNameGET /api/v1/supabase/tables/:tableName/existsPOST /api/v1/supabase/tables/:tableName/dataRequest body:
{
"id": "123e4567-e89b-12d3-a456-426614174000",
"name": "John Doe",
"email": "[email protected]"
}GET /api/v1/supabase/tables/:tableName/dataDELETE /api/v1/supabase/tables/:tableName/data/:idThe API uses a consistent error response format:
{
"error": {
"message": "Error message",
"code": "ERROR_CODE",
"details": {} // Optional additional error details
}
}Common error codes:
MISSING_CREDENTIALS: Supabase credentials not configuredINVALID_REQUEST: Invalid request parametersDATABASE_ERROR: Error from SupabaseNOT_FOUND: Resource not foundINTERNAL_ERROR: Server error
npm testnpm run devnpm run buildSwagger documentation is available at:
http://localhost:3000/api-docs
src/
├── config/ # Configuration files
├── infrastructure/ # Infrastructure layer (repositories, factories)
│ ├── factory/ # Factory implementations
│ └── repository/ # Repository implementations
├── middleware/ # Express middleware
├── presentation/ # Presentation layer (controllers, routes)
│ ├── controller/ # Controller implementations
│ └── route/ # Route definitions
└── types/ # TypeScript type definitions
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request