Skip to content

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

Merged
cpojer merged 1 commit into
voidzero-dev:mainfrom
niteshseram:fix/typed-fetch-required-method
Nov 7, 2026
Merged

cpojer merged 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.

@cpojer cpojer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 Thank you.

@cpojer
cpojer merged commit ac071b5 into voidzero-dev:main Nov 7, 2026
2 checks passed
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.

2 participants