Unify the web Response binding into Fetch.Response#26
Merged
Conversation
App Router route handlers return a web `Response`, but the bindings had no way to construct one — only the read side (`FetchResponse`, what `fetch` resolves to). It's one Web API type, so rather than add a second type for it, fold the construct side into the existing record module: - Rename `FetchResponse` -> `Response`, kept as a deprecated `module FetchResponse = Response` alias so existing consumers keep compiling. - Add `make(body, init)` (`new Response`, nullable body, init status/statusText/headers) and the static `redirect(url, status)`. - Add a `headers: Headers.t` read field (response headers weren't readable). - `fetch` now returns `Response.t`. Headers are typed `Headers.t` (consistent with NextServer.NextResponse.options), not a dict. Read access (`res.status`, `res.json()`) is unchanged, so this is non-breaking for read consumers; the only theoretical break — constructing a `FetchResponse.t` record literal — occurs nowhere in rescript-next, njc, or vialab. Tested against the runtime.
reebalazs
force-pushed
the
web-response-binding
branch
from
June 25, 2026 08:38
6f8caa3 to
7fb7e52
Compare
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.
App Router route handlers return a web
Response, but the bindings had no way to construct one — only the read side (FetchResponse, whatfetchresolves to). Since it's one Web API type, this folds the construct side into the existing record module rather than adding a second type.What
FetchResponse→Response, kept as a deprecatedmodule FetchResponse = Responsealias so existing consumers keep compiling.make(body, init)(new Response; bodyNullable.t<string>,init = {status?, statusText?, headers?: Headers.t}) and the staticredirect(url, status).headers: Headers.tread field — response headers weren't readable at all before.fetchnow returnsResponse.t.Headers are typed
Headers.t(consistent withNextServer.NextResponse.options), not a dict.Breaking-change analysis
The record stays a record, so read access is unchanged (
res.status,res.json()), andFetchResponsesurvives as an alias — so:res.status/res.json()FetchResponsename /fetchreturn typeheadersfieldFetchResponse.trecord literalThe one theoretical break (record-literal construction) has zero occurrences across rescript-next, njc, and vialab (checked: vialab consumes only
Fetch.Headers+fetchJson, neverFetchResponse).Tested against the runtime (status + headers round-trip for
makeandredirect). No version bump (left for the release).