This document provides a comprehensive overview of the DefiFundr API, including endpoints, authentication, request/response formats, and error handling.
The DefiFundr API follows RESTful principles and uses JSON for request and response payloads. The API is organized around resources and supports standard HTTP methods:
GET- Retrieve resourcesPOST- Create resourcesPUT- Update resources (full update)PATCH- Update resources (partial update)DELETE- Delete resources
The base URL for all API endpoints is:
https://api.defifundr.com/v1
For local development:
http://localhost:8080/v1
The API uses PASETO (Platform-Agnostic Security Tokens) for authentication. To access protected endpoints:
- Obtain an access token by authenticating at
/v1/auth/login - Include the token in the
Authorizationheader of subsequent requests:
Authorization: Bearer [YOUR_TOKEN]
- Token Expiration: Access tokens expire after 15 minutes
- Token Refresh: Use the refresh token endpoint
/v1/auth/refreshto obtain a new access token - Token Revocation: Tokens can be invalidated at
/v1/auth/logout
Requests with a body should use JSON format with the Content-Type: application/json header.
Example request:
{
"email": "user@example.com",
"password": "SecurePassword123"
}Successful responses return a JSON object with the following structure:
{
"status": "success",
"data": {
// Response data specific to the endpoint
}
}Endpoints that return collections support pagination with the following query parameters:
page: Page number (1-based)limit: Items per page (default: 10, max: 100)
Paginated responses include metadata:
{
"status": "success",
"data": [...],
"meta": {
"page": 1,
"limit": 10,
"total": 42,
"pages": 5
}
}Errors return appropriate HTTP status codes and a JSON object with error details:
{
"status": "error",
"error": {
"code": "unauthorized",
"message": "Invalid authentication credentials"
}
}| HTTP Status | Error Code | Description |
|---|---|---|
| 400 | bad_request | Invalid request parameters |
| 401 | unauthorized | Authentication required or invalid token |
| 403 | forbidden | Permission denied |
| 404 | not_found | Resource not found |
| 409 | conflict | Resource conflict |
| 422 | validation_error | Validation failed |
| 429 | rate_limited | Too many requests |
| 500 | server_error | Internal server error |
The API implements rate limiting to prevent abuse. Limits are applied per API key/IP address.
Rate limit headers are included in all responses:
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 99
X-RateLimit-Reset: 1620000000
When rate limited, you'll receive a 429 Too Many Requests response.
API versions are specified in the URL path (e.g., /v1/users). When breaking changes are necessary, a new API version will be released.
Interactive API documentation is available through Swagger UI. To generate and access the Swagger documentation:
-
Generate Swagger documentation:
make swagger
-
Access the Swagger UI at:
http://localhost:8080/swagger/index.html
The Swagger documentation provides:
- Interactive endpoint testing
- Request/response schemas
- Authentication information
- Example requests
cmd/api/docs/swagger.json- Swagger specification in JSON formatcmd/api/docs/swagger.yaml- Swagger specification in YAML formatcmd/api/docs/docs.go- Go code for Swagger integration