Skip to content

feat: support Next.js API and NestJS responses - #9

Merged
3m1n3nc3 merged 2 commits into
mainfrom
feat/nextjs-nestjs-response
Nov 5, 2026
Merged

3m1n3nc3 merged 2 commits into
mainfrom
feat/nextjs-nestjs-response

Conversation

@3m1n3nc3

@3m1n3nc3 3m1n3nc3 commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Closes the last open roadmap item: direct support for Next.js API and NestJS response objects in withResponse(), .response() and ServerResponse.

Next.js

  • Pages Router API routes: a NextApiResponseLike type, with response() and ServerResponse overloads. Resora sends through res.status() / res.send() and reads the status text from res.statusMessage. A { req, res } context also gives Resora the request path for pagination links.
  • App Router route handlers: these return a Web Response and have no mutable response object, so ServerResponse gets toWebResponse(). It resolves async data(), runs beforeSend hooks, and returns a JSON Response with the body, status, status text and headers. Content-Type defaults to application/json.
export async function GET() {
  return new UserResource(await findUser()).response().setStatusCode(200).toWebResponse()
}

NestJS

Nest's @Res() response is already an Express res or a Fastify reply, which Resora supports. This adds a NestHttpHostLike type so an ArgumentsHost or ExecutionContext (from interceptors, guards and exception filters) works as the response or the context:

  • extractResponseFromCtx and extractRequestUrl read the response and request from switchToHttp().
  • resolveRawResponse unwraps a host passed to .response(host).
  • response(host: NestHttpHostLike) overloads on Resource, ResourceCollection and GenericResource.

Docs

  • Next.js and NestJS sections in the non-Connect frameworks guide, replacing the old NestJS "recommended pattern".
  • toWebResponse() in the ServerResponse guide and API page.
  • Changelog entries, and the roadmap item is marked as implemented.

Tests

  • tests/nextjs.spec.ts: Pages Router routes run on a Node handler that adds status(), send() and json() like Next does; App Router tests check toWebResponse().
  • tests/nestjs.spec.ts: a host shaped like Nest's ExecutionContextHost over Express and Fastify.

These don't install next or @nestjs/*; they use the same shapes those frameworks pass in.

pnpm test (234 passed), pnpm lint and pnpm build pass.

@3m1n3nc3 3m1n3nc3 self-assigned this Nov 5, 2026
@codecov

codecov Bot commented Nov 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@3m1n3nc3
3m1n3nc3 merged commit 4a98697 into main Nov 5, 2026
4 checks passed
@3m1n3nc3
3m1n3nc3 deleted the feat/nextjs-nestjs-response branch November 5, 2026 12:59
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