Skip to content

feat(nest): add Hono framework support#1299

Merged
dinwwwh merged 4 commits into
middleapi:mainfrom
Mnigos:fix/hono-adapter-interceptor-response
May 4, 2026
Merged

feat(nest): add Hono framework support#1299
dinwwwh merged 4 commits into
middleapi:mainfrom
Mnigos:fix/hono-adapter-interceptor-response

Conversation

@Mnigos
Copy link
Copy Markdown
Contributor

@Mnigos Mnigos commented Dec 14, 2025

Summary

Adds Hono-based HTTP adapter support to @orpc/nest so @Implement routes can run in Nest applications backed by a Hono adapter.

Changes

  • Added Fetch request/response handling for Hono adapter contexts via @orpc/standard-server-fetch.
  • Detects Hono response contexts by their Fetch response factory and returns a Hono-native Response with newResponse(...).
  • Adds OPTIONS route decorator support for implemented contract routes.
  • Adds compatibility coverage using @mnigos/platform-hono@^0.1.3, including request body/query/header parsing, route params, response headers, and error responses.
  • Documents Hono-based adapter usage with @mnigos/platform-hono as an example.

Summary by CodeRabbit

  • New Features

    • Added runtime support for Hono adapters so the package can run on Hono-powered servers alongside existing environments.
    • Interceptor now routes and converts requests/responses correctly across supported adapters.
  • Documentation

    • New guide section on using the Hono adapter with recommended configuration notes.
  • Tests

    • Added compatibility tests verifying handlers and routes work when the app runs with the Hono adapter.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Dec 14, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 14, 2025

📝 Walkthrough

Walkthrough

Added Hono adapter support to the Nest ImplementInterceptor and workspace/dev dependencies; interceptor now detects runtime adapter (Hono / Fastify / Node) and branches request/response conversion through the corresponding StandardServer adapter. Added a Hono compatibility test and documentation section.

Changes

Nest Hono + multi-adapter integration

Layer / File(s) Summary
Dependency
packages/nest/package.json
Added dependency @orpc/standard-server-fetch and devDependencies @hono/node-server, @mnigos/platform-hono, and hono.
Types / Imports
packages/nest/src/implement.ts
Imported StandardServerFetch; introduced HonoContext shape and expanded req/res unions to include Hono surface.
Core Runtime Branching
packages/nest/src/implement.ts
Added runtime detection (isHono, isFastify) and branching to create standardRequest via StandardServerFetch.toStandardLazyRequest (Hono), StandardServerFastify.toStandardLazyRequest (Fastify), or StandardServerNode.toStandardLazyRequest (Node/Express).
Response Handling
packages/nest/src/implement.ts
Branched response emission: Hono uses StandardServerFetch.toFetchResponse and HonoContext.newResponse; Fastify/Node use existing sendStandardResponse helpers.
Parameter Handling
packages/nest/src/implement.ts
flattenParams signature changed to accept `NestParams
Tests
packages/nest/src/implement.test.ts
Added compatibility test works with @mnigos/platform-hono`` that boots Nest with HonoAdapter (bodyParser:false), exercises `/ping`, `/pong/:name`, `/world/:path`, and asserts responses and handler call payloads.
Documentation
apps/content/docs/.../implement-contract-in-nest.md
Added “Hono Adapter” section documenting install, using HonoAdapter with NestFactory.create, keeping bodyParser: false, and behavior notes for @Implement routes.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant Interceptor as ImplementInterceptor
    participant Adapters as Standard Adapters
    participant AdapterCtx as Adapter Context / Server
    Client->>Interceptor: HTTP request
    Interceptor->>Interceptor: detect adapter (isHono / isFastify / else Node)
    alt Hono
        Interceptor->>AdapterCtx: use req.raw via HonoContext
        Interceptor->>Adapters: StandardServerFetch.toStandardLazyRequest(req.raw)
        Adapters-->>Interceptor: standardRequest
        Interceptor->>Adapters: execute handler -> standardResponse
        Interceptor->>Adapters: StandardServerFetch.toFetchResponse(standardResponse)
        Adapters-->>AdapterCtx: AdapterCtx.newResponse(fetchResponse)
    else Fastify
        Interceptor->>AdapterCtx: use Fastify req/res
        Interceptor->>Adapters: StandardServerFastify.toStandardLazyRequest(req,res)
        Adapters-->>Interceptor: standardRequest
        Interceptor->>Adapters: StandardServerFastify.sendStandardResponse(res, standardResponse)
    else Node/Express
        Interceptor->>AdapterCtx: use Node req/res
        Interceptor->>Adapters: StandardServerNode.toStandardLazyRequest(req,res)
        Adapters-->>Interceptor: standardRequest
        Interceptor->>Adapters: StandardServerNode.sendStandardResponse(res, standardResponse)
    end
    AdapterCtx-->>Client: HTTP response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

size:L

Poem

🐇 I twitched my whiskers in HTTP light,
Hono, Fastify, Node — I hopped each site.
One interceptor nose, three pathways to roam,
I turn requests to replies and bring them home. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(nest): add Hono framework support' accurately captures the main objective of the PR: adding Hono adapter support to @orpc/nest for implementing HTTP routes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Mnigos, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the @orpc/nest package by introducing support for the Hono HTTP adapter. The primary goal is to allow oRPC contracts to function correctly within NestJS applications that leverage the Hono framework, particularly through @kiyasov/platform-hono. The changes involve adapting the core request and response handling mechanisms to align with Hono's fetch-based API, ensuring that applications can utilize Hono's performance benefits without requiring manual configuration for oRPC integration.

Highlights

  • Hono Framework Support: Added comprehensive support for the Hono HTTP adapter within the @orpc/nest package, enabling oRPC contracts to seamlessly integrate with NestJS applications utilizing @kiyasov/platform-hono.
  • Dependency Addition: Introduced the @orpc/standard-server-fetch dependency to handle fetch-based request and response processing, which is crucial for Hono's architecture.
  • Dynamic Adapter Detection: Implemented logic to automatically detect the Hono adapter by checking for specific properties (finalized and newResponse method) on the response context, allowing for adaptive request and response handling.
  • Request and Response Conversion: Integrated toStandardLazyRequest from standard-server-fetch for converting Hono requests into a standard format and toFetchResponse for setting the response on the Hono context.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for the Hono framework to @orpc/nest. The changes correctly detect the Hono environment through duck-typing and use @orpc/standard-server-fetch to handle requests and responses. The implementation looks solid. I've provided a few suggestions to improve type correctness and code readability.

Comment thread packages/nest/src/implement.ts Outdated
Comment thread packages/nest/src/implement.ts
Comment thread packages/nest/src/implement.ts Outdated
- Add @orpc/standard-server-fetch dependency
- Add HonoContext interface for Hono framework detection
- Extend ImplementInterceptor to handle Hono requests and responses
- Support Hono adapter in interceptor response handling
@Mnigos Mnigos force-pushed the fix/hono-adapter-interceptor-response branch from a95114e to 975b04c Compare December 14, 2025 18:48
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
packages/nest/src/implement.ts (1)

136-137: Add explanatory comment for the duck-typing detection logic.

The detection logic is correct, but relies on duck-typing which is fragile if underlying frameworks change. As noted in a previous review, add a comment explaining this coupling:

+        // Detect Hono adapter by checking for properties on the response context.
+        // This is coupled with `@kiyasov/platform-hono`.
+        // See: https://github.com/kiyasov/platform-hono/pull/10
         const isHono = 'finalized' in res && typeof (res as HonoContext).newResponse === 'function'
+        // Fastify also has `raw` on request, so exclude Hono first
         const isFastify = 'raw' in req && !isHono
🧹 Nitpick comments (1)
packages/nest/src/implement.ts (1)

24-29: Well-defined minimal interface.

The interface correctly models only the relevant Hono context surface area. The optional res property accurately reflects that it's assigned by the interceptor rather than being initially present.

Consider adding a brief JSDoc comment explaining this interface's purpose and its coupling to @kiyasov/platform-hono:

+/**
+ * Minimal interface for Hono-like request/response context.
+ * Coupled with @kiyasov/platform-hono behavior.
+ * @see https://github.com/kiyasov/platform-hono/pull/10
+ */
 interface HonoContext {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a95114e and 975b04c.

📒 Files selected for processing (2)
  • packages/nest/package.json (1 hunks)
  • packages/nest/src/implement.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/nest/package.json
🧰 Additional context used
🧬 Code graph analysis (1)
packages/nest/src/implement.ts (1)
packages/standard-server-fastify/src/index.ts (1)
  • FastifyRequest (4-4)
🔇 Additional comments (3)
packages/nest/src/implement.ts (3)

18-18: LGTM!

Import correctly added alongside other standard server adapters. The @orpc/standard-server-fetch package is appropriate for Hono's web-standard Request/Response handling.


139-147: LGTM!

The IIFE pattern cleanly implements the multi-platform request handling. The branch order correctly mirrors the detection logic, and type assertions are safe given the preceding runtime checks.


168-176: Response handling correctly adapts to each platform.

The Hono branch correctly uses synchronous assignment since toFetchResponse returns immediately and @kiyasov/platform-hono picks up the res property. The Fastify and Node branches appropriately await the stream-based sendStandardResponse.

Copy link
Copy Markdown
Member

@dinwwwh dinwwwh left a comment

Choose a reason for hiding this comment

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

Please add tests for this feature, include routing matching and update the docs

Comment thread packages/nest/src/implement.ts Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/nest/src/implement.test.ts (1)

700-736: ⚡ Quick win

Add one Hono assertion for dynamic/overridden status propagation.

This test covers happy-path/error-path well, but it doesn’t yet pin the Hono-specific response conversion for custom statuses. A regression in toFetchResponse/newResponse could still pass here. Add a request where ping_handler returns status: 203 (or a sendResponseInterceptor override) and assert the HTTP status.

Suggested test addition
       try {
         const pingRes = await supertest(httpServer)
           .post('/ping?param=value&param2[]=value2&param2[]=value3')
           .set('x-custom', 'value')
           .send({ hello: 'world' })

         expect(pingRes.statusCode).toEqual(200)
         expect(pingRes.body).toEqual('pong')
         expect(pingRes.headers).toEqual(expect.objectContaining({ 'x-ping': 'pong' }))
+        
+        ping_handler.mockResolvedValueOnce({ body: 'pong', headers: { 'x-ping': 'pong' }, status: 203 } as any)
+        const ping203Res = await supertest(httpServer)
+          .post('/ping?param=value')
+          .send({ hello: 'world' })
+        expect(ping203Res.statusCode).toEqual(203)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/nest/src/implement.test.ts` around lines 700 - 736, Add an assertion
that verifies Hono-specific status propagation by creating a request where
ping_handler returns a non-default status (e.g., status: 203) or by using the
sendResponseInterceptor to override the response status, then send that request
in the same test block and assert the HTTP status equals 203; locate the
existing pingRes/ping_handler usage in the test (references: ping_handler and
pong_handler) and add a new supertest call and
expect(...statusCode).toEqual(203) to ensure toFetchResponse/newResponse
correctly preserves custom statuses.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/nest/src/implement.test.ts`:
- Around line 700-736: Add an assertion that verifies Hono-specific status
propagation by creating a request where ping_handler returns a non-default
status (e.g., status: 203) or by using the sendResponseInterceptor to override
the response status, then send that request in the same test block and assert
the HTTP status equals 203; locate the existing pingRes/ping_handler usage in
the test (references: ping_handler and pong_handler) and add a new supertest
call and expect(...statusCode).toEqual(203) to ensure
toFetchResponse/newResponse correctly preserves custom statuses.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7df67dd5-3632-4482-9728-a5e59f17d089

📥 Commits

Reviewing files that changed from the base of the PR and between 975b04c and 177d4a6.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • apps/content/docs/openapi/integrations/implement-contract-in-nest.md
  • packages/nest/package.json
  • packages/nest/src/implement.test.ts
  • packages/nest/src/implement.ts
✅ Files skipped from review due to trivial changes (1)
  • apps/content/docs/openapi/integrations/implement-contract-in-nest.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/nest/src/implement.ts
  • packages/nest/package.json

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 3, 2026

More templates

@orpc/ai-sdk

npm i https://pkg.pr.new/@orpc/ai-sdk@1299

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@1299

@orpc/client

npm i https://pkg.pr.new/@orpc/client@1299

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@1299

@orpc/experimental-durable-iterator

npm i https://pkg.pr.new/@orpc/experimental-durable-iterator@1299

@orpc/hey-api

npm i https://pkg.pr.new/@orpc/hey-api@1299

@orpc/interop

npm i https://pkg.pr.new/@orpc/interop@1299

@orpc/json-schema

npm i https://pkg.pr.new/@orpc/json-schema@1299

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@1299

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@1299

@orpc/openapi-client

npm i https://pkg.pr.new/@orpc/openapi-client@1299

@orpc/otel

npm i https://pkg.pr.new/@orpc/otel@1299

@orpc/experimental-pino

npm i https://pkg.pr.new/@orpc/experimental-pino@1299

@orpc/experimental-publisher

npm i https://pkg.pr.new/@orpc/experimental-publisher@1299

@orpc/experimental-publisher-durable-object

npm i https://pkg.pr.new/@orpc/experimental-publisher-durable-object@1299

@orpc/experimental-ratelimit

npm i https://pkg.pr.new/@orpc/experimental-ratelimit@1299

@orpc/react

npm i https://pkg.pr.new/@orpc/react@1299

@orpc/react-query

npm i https://pkg.pr.new/@orpc/react-query@1299

@orpc/experimental-react-swr

npm i https://pkg.pr.new/@orpc/experimental-react-swr@1299

@orpc/server

npm i https://pkg.pr.new/@orpc/server@1299

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@1299

@orpc/solid-query

npm i https://pkg.pr.new/@orpc/solid-query@1299

@orpc/standard-server

npm i https://pkg.pr.new/@orpc/standard-server@1299

@orpc/standard-server-aws-lambda

npm i https://pkg.pr.new/@orpc/standard-server-aws-lambda@1299

@orpc/standard-server-fastify

npm i https://pkg.pr.new/@orpc/standard-server-fastify@1299

@orpc/standard-server-fetch

npm i https://pkg.pr.new/@orpc/standard-server-fetch@1299

@orpc/standard-server-node

npm i https://pkg.pr.new/@orpc/standard-server-node@1299

@orpc/standard-server-peer

npm i https://pkg.pr.new/@orpc/standard-server-peer@1299

@orpc/svelte-query

npm i https://pkg.pr.new/@orpc/svelte-query@1299

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@1299

@orpc/trpc

npm i https://pkg.pr.new/@orpc/trpc@1299

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@1299

@orpc/vue-colada

npm i https://pkg.pr.new/@orpc/vue-colada@1299

@orpc/vue-query

npm i https://pkg.pr.new/@orpc/vue-query@1299

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@1299

commit: d550b91

@codecov
Copy link
Copy Markdown

codecov Bot commented May 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Mnigos Mnigos requested a review from dinwwwh May 3, 2026 07:49
Comment thread packages/nest/src/implement.test.ts
@Mnigos Mnigos requested a review from dinwwwh May 3, 2026 10:35
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 3, 2026
@dinwwwh dinwwwh merged commit 90a4d22 into middleapi:main May 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants