Skip to content

API Overview ​

The acodeaday API is a RESTful API built with FastAPI. This reference covers all available endpoints, request/response formats, and authentication.

Base URL ​

Local Development:

http://localhost:8000

Production:

https://api.yourapp.com

All API endpoints are prefixed with /api.

Authentication ​

acodeaday uses Supabase Auth with JWT Bearer tokens.

Login Flow ​

  1. User authenticates with Supabase (email/password)
  2. Supabase returns JWT access token
  3. Client includes token in subsequent requests to backend
  4. Backend validates token with Supabase

JWT Bearer Token Header ​

http
Authorization: Bearer <access_token>

Example:

bash
curl -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..." http://localhost:8000/api/today

See Authentication for details.

Request Format ​

Content Type ​

All requests with body must use:

Content-Type: application/json

Example Request ​

bash
curl -X POST http://localhost:8000/api/submit \
  -H "Content-Type: application/json" \
  -H "Authorization: Basic YWRtaW46cGFzc3dvcmQ=" \
  -d '{
    "problem_slug": "two-sum",
    "language": "python",
    "code": "class Solution:\n    def twoSum(self, nums, target):\n        ..."
  }'

Response Format ​

All responses are JSON with consistent structure.

Success Response ​

json
{
  "success": true,
  "data": {
    // Response data here
  }
}

Error Response ​

json
{
  "success": false,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Problem not found",
    "details": {}
  }
}

HTTP Status Codes ​

CodeMeaningDescription
200OKRequest succeeded
201CreatedResource created successfully
400Bad RequestInvalid request data
401UnauthorizedMissing or invalid authentication
403ForbiddenAuthenticated but not authorized
404Not FoundResource doesn't exist
422Unprocessable EntityValidation error
500Internal Server ErrorServer error

Pagination ​

List endpoints support pagination:

http
GET /api/problems?limit=10&offset=0

Query Parameters:

  • limit - Number of items per page (default: 20, max: 100)
  • offset - Number of items to skip (default: 0)

Response:

json
{
  "items": [...],
  "total": 100,
  "limit": 10,
  "offset": 0,
  "has_more": true
}

Rate Limiting ​

Currently no rate limiting is implemented, but recommended for production:

  • 100 requests per minute per IP
  • 1000 requests per hour per user

CORS ​

CORS is configured to allow requests from:

  • Local development: http://localhost:5173
  • Production: Your frontend domain

Allowed methods: GET, POST, PUT, DELETE, OPTIONS

Endpoints Summary ​

Problems ​

MethodEndpointAuthDescription
GET/api/problemsNoList all problems
GET/api/problems/:slugNoGet problem details

Code Execution ​

MethodEndpointAuthDescription
POST/api/runNoRun code against example tests
POST/api/submitYesSubmit solution against all tests
POST/api/rate-submissionYesRate submission difficulty (Anki SM-2)

Code Persistence ​

MethodEndpointAuthDescription
POST/api/code/saveYesSave code (auto-save)
POST/api/code/resetYesReset to starter code
POST/api/code/load-submissionYesLoad past submission

User Progress ​

MethodEndpointAuthDescription
GET/api/todayYesGet daily session problems
GET/api/progressYesGet overall progress
GET/api/masteredYesGet mastered problems
POST/api/mastered/:id/show-againYesRe-add problem to rotation

Submissions ​

MethodEndpointAuthDescription
GET/api/submissions/:problem_idYesGet submission history

AI Chat ​

MethodEndpointAuthDescription
GET/api/chat/modelsNoList available LLM models
POST/api/chat/sessionsYesCreate chat session
GET/api/chat/sessions/:slugYesList sessions for problem
GET/api/chat/session/:idYesGet session with messages
POST/api/chat/session/:id/messageYesSend message to AI

Interactive Documentation ​

FastAPI provides interactive API documentation:

Swagger UI:

http://localhost:8000/docs

ReDoc:

http://localhost:8000/redoc

These interfaces allow you to:

  • Browse all endpoints
  • View request/response schemas
  • Test endpoints directly in browser
  • Download OpenAPI spec

OpenAPI Specification ​

Download the OpenAPI 3.0 spec:

http://localhost:8000/openapi.json

Use with tools like:

  • Postman (import OpenAPI spec)
  • Insomnia
  • curl
  • HTTPie

Error Codes Reference ​

CodeDescriptionResolution
VALIDATION_ERRORInvalid request dataCheck request body format
AUTHENTICATION_REQUIREDMissing authInclude Authorization header
INVALID_CREDENTIALSWrong username/passwordVerify credentials
PROBLEM_NOT_FOUNDProblem doesn't existCheck problem slug
JUDGE0_ERRORCode execution failedCheck Judge0 status
DATABASE_ERRORDatabase operation failedContact support

Data Types ​

Problem ​

typescript
{
  id: string;              // UUID
  title: string;
  slug: string;
  description: string;
  difficulty: "easy" | "medium" | "hard";
  pattern: string;
  sequence_number: number;
  constraints: string[];
  examples: Array<{
    input: string;
    output: string;
    explanation?: string;
  }>;
}

Test Case ​

typescript
{
  id: string;
  input: any[];           // Array of function arguments
  expected: any;          // Expected output
  sequence: number;
}

Submission ​

typescript
{
  id: string;
  user_id: string;
  problem_id: string;
  code: string;
  language: string;
  passed: boolean;
  runtime_ms: number;
  submitted_at: string;   // ISO 8601 timestamp
}

User Progress ​

typescript
{
  id: string;
  user_id: string;
  problem_id: string;
  times_solved: number;
  is_mastered: boolean;
  ease_factor: number;           // Anki SM-2: default 2.5, min 1.3
  interval_days: number;         // Days until next review
  review_count: number;          // Number of reviews completed
  next_review_date: string | null; // ISO 8601 date
  last_solved_at: string;         // ISO 8601 timestamp
}

Versioning ​

Currently API is v1 (implicit). Future versions will use URL versioning:

/api/v1/problems
/api/v2/problems

Next Steps ​

Explore specific endpoint documentation: