Skip to content

refactor(website): [stacked zodios removal] add sendRequest as the common request function - #7833

Draft
theosanderson-agent wants to merge 2 commits into
zodios-split/1-error-messagesfrom
zodios-split/2-request-core
Draft

theosanderson-agent wants to merge 2 commits into
zodios-split/1-error-messagesfrom
zodios-split/2-request-core

Conversation

@theosanderson-agent

@theosanderson-agent theosanderson-agent commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Stack (split of #7813; merge in order, each PR is based on the one above):

  1. refactor(website): [stacked zodios removal] unify client-side error messages with getErrorMessage #7832 unify client-side error messages with getErrorMessage
  2. → refactor(website): [stacked zodios removal] add sendRequest as the common request function #7833 add sendRequest as the common request function
  3. refactor(website): [stacked zodios removal] call the backend through backendApi on the server #7834 call the backend through backendApi on the server
  4. refactor(website): [stacked zodios removal] call LAPIS through lapisApi on the server #7835 call LAPIS through lapisApi on the server
  5. refactor(website): [stacked zodios removal] use react-query hooks for LAPIS in the browser #7836 use react-query hooks for LAPIS in the browser
  6. refactor(website): [stacked zodios removal] use react-query hooks for backend calls in submission flows #7837 use react-query hooks for backend calls in submission flows
  7. refactor(website): [stacked zodios removal] use backendApi and react-query hooks for groups #7838 use backendApi and react-query hooks for groups
  8. refactor(website): [stacked zodios removal] use react-query hooks for seqset calls #7839 use react-query hooks for seqset calls
  9. test(integration): [stacked zodios removal] check that a seqset can be saved after its accessions are validated #7842 check that a seqset can be saved after its accessions are validated
  10. fix(website): [stacked zodios removal] don't expect a response body from validate-seqset-records #7843 don't expect a response body from validate-seqset-records
  11. chore(website): [stacked zodios removal] remove the Zodios dependencies and document API calls #7840 remove the Zodios dependencies and document API calls

Part of the stack splitting #7813 (removing Zodios). Depends on the previous PR.

Changes

Adds the request function in services/apiRequest.ts that all website requests to the backend, LAPIS, and the website's own JSON routes will go through. Nothing calls it yet; follow-up PRs move callers over.

  • sendRequest(baseUrl, { method, path, data, params, headers, signal, responseType, timeout, responseSchema }) sends the request with axios and validates the response against responseSchema (if omitted, the response body is ignored). Throws AxiosError on HTTP or network errors, and ResponseValidationError if validation fails.
  • apiPath is a tagged template for paths that URL-encodes every value and throws if any are missing, preventing /undefined/... requests.
  • unvalidated<T>() skips validation, for very large responses only (see zodios async zod validation of request and response can use hundreds of MB and block event loop for seconds #7752).
  • toFormData converts an object to multipart form data.
  • Server-side requests time out after 30 seconds (SERVER_SIDE_TIMEOUT_MS) so an unresponsive service can't block page rendering. Browser requests have no default timeout since they include large uploads and downloads.
  • getErrorMessage now also handles ResponseValidationError without exposing zod details to users.

Also adds request body types inferred from the zod schemas (SubmitFiles, SetDataUseTermsRequest, CreateSeqSetRequest, ...) and a LapisRequest type. Using LapisRequest instead of the inferred LapisBaseRequest when building requests in code lets later PRs in the stack drop the @ts-expect-errors for zod issue 3136.

Review notes

This PR settles the core design choices: we validate responses, no longer validate request bodies before sending them, and put a timeout on server-side requests.

Testing

Type check, lint, and unit tests pass on this commit.

Review follow-up

apiPath also rejects NaN values (separate commit), so paths like /groups/NaN can't be built. apiRequest.spec.ts has new tests for apiPath.

🤖 Generated with Claude Code

Add sendRequest, apiPath, toFormData, unvalidated and
ResponseValidationError to services/apiRequest.ts, plus request body
types inferred from the zod schemas. Nothing uses them yet; later PRs
move the callers over.

Split out of #7813.

Co-Authored-By: Anna (Anya) Parker <50943381+anna-parker@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

This PR may be related to: #7818

@theosanderson-agent theosanderson-agent changed the title refactor(website): add sendRequest as the common request function refactor(website): [stacked zodios removal] add sendRequest as the common request function Nov 19, 2026
Comment thread website/src/services/apiRequest.ts Resolved
Comment thread website/src/services/apiRequest.ts Resolved
Comment thread website/src/services/apiRequest.ts Resolved
apiPath rejected undefined, null and empty values, but NaN passed and
produced paths like /groups/NaN. Throw for NaN too, and add unit tests
for apiPath.

Reported in review of #7833.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

website Tasks related to the web application

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants