Skip to content

Standardize API Response Format Across All Backend Endpoints#51

Open
androemeda wants to merge 1 commit intovirtualcell:mainfrom
androemeda:feature/standardize-api-responses
Open

Standardize API Response Format Across All Backend Endpoints#51
androemeda wants to merge 1 commit intovirtualcell:mainfrom
androemeda:feature/standardize-api-responses

Conversation

@androemeda
Copy link

Summary

This PR introduces a standardized API response format across all backend endpoints to improve consistency, debugging, and frontend integration. All responses now follow a uniform structure that includes a success flag, timestamp, optional message, and metadata when relevant.

Implementation

ResponseFormatter Utility

  • Added a centralized ResponseFormatter utility with:
    • success_response()
    • error_response()
  • Ensures consistent structure for all API responses.

Controller Updates

  • Updated all backend controllers to use the new response format:
    • LLM Controller
    • VCell Database Controller
    • Knowledge Base Controller

Error Handling

  • Simplified error responses while preserving correct HTTP status codes.
  • Ensures predictable error structures for frontend handling and debugging.

Backward Compatibility

  • Updated the frontend ChatBox component to support both old and new response formats during the transition phase.
  • Prevents breaking changes while the system migrates to the standardized format.

Response Format

Before (Inconsistent formats)

// LLM endpoint
{"response": "...", "bmkeys": [...]}

// VCell endpoint
{"data": [...], "models_count": 50}

// Knowledge Base endpoint
{"files": [...]}

After (Standardized format)

Success Response

{
  "success": true,
  "data": {...},
  "message": "Request completed successfully",
  "timestamp": "2026-03-12T10:30:45.123Z",
  "meta": {
    "bmkeys": [...]
  } // Included only when relevant
}

Error Response

{
  "success": false,
  "data": null,
  "message": "Failed to fetch biomodels from VCell API",
  "timestamp": "2026-03-12T10:30:45.123Z"
}

Testing

  • Syntax Validation: All controller files pass Python compilation checks.
  • Frontend Integration: Updated ChatBox component works with the new response structure.
  • Error Handling: Existing error conditions preserved with improved consistency.
  • Backward Compatibility: No breaking changes introduced to existing API contracts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant