Solve : Standardize API Response Format #33
Open
linisha15 wants to merge 1 commit intoOSeMOSYS:masterfrom
Open
Solve : Standardize API Response Format #33linisha15 wants to merge 1 commit intoOSeMOSYS:masterfrom
linisha15 wants to merge 1 commit intoOSeMOSYS:masterfrom
Conversation
|
I noticed that PR #32 (global error handlers for #28) is being worked on in parallel and currently builds the error response structure manually. Since both changes appear to aim for the same standardized schema, it might be helpful to consider aligning that PR to use this helper as well, so the standardization is consistent end-to-end. Just suggesting this in case it helps keep everything unified |
Author
|
@arnchlmcodes Thanks for pointing that out! I agree that aligning both PRs would help keep the schema consistent. I'm happy to coordinate or help refactor PR #32 to use this helper if that makes sense. |
This was referenced Feb 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #24
Description
This PR introduces a standardized JSON response schema across all Flask API endpoints to ensure consistent response structures.
Currently, some endpoints return raw data (e.g., return jsonify(data), 200), while others return structured objects such as:
{
"message": "...",
"status_code": "success"
}
This inconsistency makes frontend integration and future maintenance more difficult, as consumers of the API cannot rely on a predictable response format.
🚀 Proposed Solution
A helper utility function api_response() has been introduced to enforce a consistent response schema across endpoints.
Standard Success Response
{
"success": true,
"message": "Optional human-readable message",
"data": { ... },
"error": null
}
Standard Error Response
{
"success": false,
"message": "Error description",
"data": null,
"error": "Detailed error info (optional)"
}
🛠 Implementation Details
Added a reusable helper function: api_response(success, message=None, data=None, error=None, status_code=200)
Refactored selected routes to use the new standardized response format
Preserved existing HTTP status codes (200, 400, 404, 500, etc.)
No endpoint URLs were changed
Example helper implementation:
from flask import jsonify
def api_response(success, message=None, data=None, error=None, status_code=200):
response = {
"success": success,
"message": message,
"data": data,
"error": error
}
return jsonify(response), status_code