Skip to content

Phase:1- Refactoring #90

Merged
Ayush8923 merged 4 commits intomainfrom
feat/refactor-routes-phase-1
Mar 26, 2026
Merged

Phase:1- Refactoring #90
Ayush8923 merged 4 commits intomainfrom
feat/refactor-routes-phase-1

Conversation

@Ayush8923
Copy link
Copy Markdown
Collaborator

@Ayush8923 Ayush8923 commented Mar 24, 2026

Isssue: #71

Summary:

  • Use the common function to apiClient function in the route.ts file.
  • Update the apiClient function if the form-data body then we don't need to include the Content-type in the header, in this case the browser automatically sets the Content-Type like this:
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryXYZ

Summary by CodeRabbit

Release Notes

  • Refactor
    • Consolidated backend API request handling across multiple endpoints through a shared utility helper, reducing code duplication and ensuring consistent authentication and error handling across all API routes.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 24, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR refactors multiple API route handlers to delegate backend HTTP proxying to a shared apiClient helper, removing manual fetch calls, direct X-API-KEY header extraction, and explicit backend URL construction from 14+ route files. The apiClient utility itself receives minor updates for improved FormData and response parsing handling.

Changes

Cohort / File(s) Summary
Assistant routes
app/api/assistant/[assistant_id]/route.ts
Refactored GET handler to use apiClient instead of manual fetch, removing backend URL construction and X-API-KEY header forwarding.
Collections routes
app/api/collections/route.ts, app/api/collections/[collection_id]/route.ts, app/api/collections/jobs/[job_id]/route.ts
Updated all GET/POST/DELETE handlers to delegate proxying to apiClient, removing manual backend URL and X-API-KEY handling; simplified response parsing.
Configs routes
app/api/configs/route.ts, app/api/configs/[config_id]/route.ts, app/api/configs/[config_id]/versions/route.ts, app/api/configs/[config_id]/versions/[version_number]/route.ts
Refactored GET/POST/PATCH/DELETE handlers to use apiClient; changed some handlers from NextRequest to Request type; removed direct backend access logic.
Document routes
app/api/document/route.ts, app/api/document/[document_id]/route.ts
Delegated GET/POST/DELETE handlers to apiClient, removing manual fetch and header extraction.
Evaluations core routes
app/api/evaluations/route.ts, app/api/evaluations/[id]/route.ts
Added apiClient delegation for GET/POST; in [id]/route.ts, introduced new getMockEvaluation() helper for mock-data mode and refactored backend path handling.
Evaluations dataset routes
app/api/evaluations/datasets/route.ts, app/api/evaluations/datasets/[dataset_id]/route.ts
Refactored GET/POST/DELETE handlers to use apiClient; retained CSV fetch_content behavior and multipart upload support via formData forwarding.
Evaluations STT routes
app/api/evaluations/stt/datasets/route.ts, app/api/evaluations/stt/datasets/[dataset_id]/route.ts, app/api/evaluations/stt/runs/route.ts, app/api/evaluations/stt/runs/[run_id]/route.ts, app/api/evaluations/stt/results/[result_id]/route.ts, app/api/evaluations/stt/samples/[sample_id]/route.ts
Updated all GET/POST/PATCH/DELETE handlers to delegate to apiClient; removed explicit X-API-KEY validation from most (except one POST that still validates); changed some handlers from NextRequest to Request.
Shared API client utility
app/lib/apiClient.ts
Simplified BACKEND_URL declaration; improved Content-Type handling to avoid overriding FormData boundary; changed response parsing to read text first, then JSON-parse only if non-empty.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • UI: STT Evals #44: Both PRs modify app/api/evaluations/stt/datasets/route.ts—this PR refactors it to use the shared apiClient, while the retrieved PR added the original manual fetch implementation.
  • API management centralize store #89: Both PRs migrate route and page code to use the shared apiClient/apiFetch utilities, with overlapping changes at the API client and route-level integration.
  • UI overhaul #69: Both PRs modify app/api/evaluations/datasets/[dataset_id]/route.ts—this PR refactors those GET/DELETE handlers to use apiClient, while the retrieved PR originally added the manual backend proxying and CSV content handling.

Suggested reviewers

  • Prajna1999
  • vprashrex

Poem

🐰 In routes both far and routes both near,
We bundled fetch calls loud and clear,
With apiClient as our guiding light,
Each proxy now delegates just right!
No more X-API-KEY scattered wide—
One shared helper's our steady guide.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 31.58% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title "Phase:1- Refactoring" is vague and generic, using non-descriptive terms that fail to convey the specific nature of the changeset. Replace with a more specific title that describes the main change, such as 'Refactor API routes to use shared apiClient helper' or 'Consolidate backend proxying logic into apiClient utility'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/refactor-routes-phase-1

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Ayush8923 Ayush8923 self-assigned this Mar 24, 2026
// Set to true to use mock data, false to use real backend
const USE_MOCK_DATA = false;

// === MOCK DATA (remove this section when no longer needed) ===
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think mock data Is needed .. I guess initially it was created for some testing purposes .. now I this can be removed

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will remove this.

Base automatically changed from feat/api-management-centralize-storage to main March 26, 2026 14:26
@Ayush8923 Ayush8923 merged commit 80d0ae6 into main Mar 26, 2026
1 check passed
@Ayush8923 Ayush8923 deleted the feat/refactor-routes-phase-1 branch March 26, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants