Overview
Every Gainable app includes automatically generated API endpoints. These APIs power your app’s functionality and can be used by external integrations.You don’t need to know about APIs to use Gainable. This reference is for users who want to understand how their apps work internally or integrate with external systems.
API structure
For each data model you create, Gainable generates RESTful endpoints:| Endpoint | Method | Description |
|---|---|---|
/api/{model} | GET | List all items |
/api/{model} | POST | Create new item |
/api/{model}/:id | GET | Get single item |
/api/{model}/:id | PUT | Update item |
/api/{model}/:id | DELETE | Delete item |
Example
If you create a Deal model, you get:| Endpoint | Method | Description |
|---|---|---|
/api/deal | GET | List all deals |
/api/deal | POST | Create new deal |
/api/deal/:id | GET | Get specific deal |
/api/deal/:id | PUT | Update deal |
/api/deal/:id | DELETE | Delete deal |
Response format
All API responses follow this structure:Success response
List response
Error response
Common operations
Create an item
Update an item
Delete an item
Filtering
Most list endpoints support query parameters for filtering:Real-time events
When data changes, the server broadcasts events via WebSocket:| Event | Payload | When |
|---|---|---|
{model}:created | New item | Item is created |
{model}:updated | Updated item | Item is modified |
{model}:deleted | Deleted item ID | Item is deleted |
Example events
Authentication
API requests require authentication. Your app handles this automatically through session cookies when accessed through the browser. For external integrations, contact support for API key access.Rate limits
APIs have reasonable rate limits to ensure stability:- Standard: 100 requests per minute
- Bulk operations: 10 requests per minute
Data types
Automatic fields
Every item includes:| Field | Type | Description |
|---|---|---|
_id | ObjectId | Unique identifier |
createdAt | Date | Creation timestamp |
updatedAt | Date | Last update timestamp |
Reference fields
When models reference each other, the API returns IDs:Best practices
Use the UI when possible
Use the UI when possible
The app’s UI is the easiest way to interact with your data. Use APIs only when you need external integration.
Handle errors gracefully
Handle errors gracefully
Check for
success: false responses and handle them appropriately.Use real-time events
Use real-time events
Instead of polling, listen for WebSocket events to get instant updates.