Skip to content

fix(client): require explicit methods for non-GET requests - #734

Open
niteshseram wants to merge 1 commit into
voidzero-dev:mainfrom
niteshseram:fix/typed-fetch-required-method
Open

niteshseram wants to merge 1 commit into
voidzero-dev:mainfrom
niteshseram:fix/typed-fetch-required-method

Conversation

@niteshseram

Copy link
Copy Markdown
Contributor

The typed fetch client accepts calls to POST-only routes without a method. These calls pass typechecking but send GET, so the POST handler never runs.

For a route that only exports POST, both calls previously compiled:

await fetch('/api/rebuild', {});
await fetch<'/api/rebuild', 'POST'>('/api/rebuild', {});

Both send GET. The POST type argument only affects TypeScript; it does not set the request method.

Cause

The fetch types made method optional for every request and allowed calls without options even when the route had no GET handler.

Fix

Require an explicit method for non-GET requests. The calls above now produce a missing-method error, while the correct call continues to work:

await fetch('/api/rebuild', { method: 'POST' });

Also clarify the requirement in the typed fetch documentation.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant