Repository navigation
refactor(website): [stacked zodios removal] add sendRequest as the common request function - #7833
Draft
theosanderson-agent wants to merge 2 commits into
Draft
theosanderson-agent wants to merge 2 commits into
theosanderson-agent wants to merge 2 commits into
Conversation
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>
This was referenced Nov 19, 2026
Draft
Draft
Draft
Contributor
|
This PR may be related to: #7818 |
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
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.
Stack (split of #7813; merge in order, each PR is based on the one above):
Part of the stack splitting #7813 (removing Zodios). Depends on the previous PR.
Changes
Adds the request function in
services/apiRequest.tsthat 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 againstresponseSchema(if omitted, the response body is ignored). ThrowsAxiosErroron HTTP or network errors, andResponseValidationErrorif validation fails.apiPathis 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).toFormDataconverts an object to multipart form data.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.getErrorMessagenow also handlesResponseValidationErrorwithout exposing zod details to users.Also adds request body types inferred from the zod schemas (
SubmitFiles,SetDataUseTermsRequest,CreateSeqSetRequest, ...) and aLapisRequesttype. UsingLapisRequestinstead of the inferredLapisBaseRequestwhen 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
apiPathalso rejectsNaNvalues (separate commit), so paths like/groups/NaNcan't be built.apiRequest.spec.tshas new tests forapiPath.🤖 Generated with Claude Code