Skip to content

refactor: Rename withResponse to respond (matches connect/hijack) - #134

Merged
nielsenko merged 1 commit into
serverpod:mainfrom
nielsenko:respond
Aug 28, 2025
Merged

nielsenko merged 1 commit into
serverpod:mainfrom
nielsenko:respond

Conversation

@nielsenko

@nielsenko nielsenko commented Aug 28, 2025 •

Copy link
Copy Markdown
Collaborator

Description

Rename RespondableContext.withResponse to RespondableContext.respond . This aligns better with name of the member used, when setting up web socket connections NewContext.connect.

Pre-Launch Checklist

Please ensure that your PR meets the following requirements before submitting:

  • This update focuses on a single feature or bug fix. (For multiple fixes, please submit separate PRs.)
  • I have read and followed the Dart Style Guide and formatted the code using dart format.
  • I have referenced at least one issue this PR fixes or is related to.
  • I have updated/added relevant documentation (doc comments with ///), ensuring consistency with existing project documentation.
  • I have added new tests to verify the changes.
  • All existing and new tests pass successfully.
  • I have documented any breaking changes below.

Breaking Changes

  • Includes breaking changes.
  • No breaking changes.

This PR renames a public method.

Summary by CodeRabbit

  • Refactor

    • Renamed the context API from withResponse(...) to respond(...). Update any handlers, middleware, and static file responses to use ctx.respond(...). No behavior changes.
  • Documentation

    • Updated references to reflect the respond(...) API.
  • Tests

    • Updated test suites to use respond(...) consistently.
  • Chores

    • Internal codebase aligned to the new respond(...) naming across modules for consistency.

@coderabbitai

coderabbitai Bot commented Aug 28, 2025 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbit review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

Renames the context API method from withResponse(...) to respond(...) across the core context types and all call sites, including handlers, middleware, server code, example, and tests. Public signatures in lib/src/adapter/context.dart are updated accordingly. No control flow or behavior changes are introduced.

Changes

Cohort / File(s) Summary of changes
Context API rename
lib/src/adapter/context.dart
Renamed withResponse(...) to respond(...) on RespondableContext, NewContext, and ResponseContext; updated docs/comments.
Core call sites
lib/src/handler/handler.dart, lib/src/io/static/static_handler.dart, lib/src/middleware/middleware.dart, lib/src/relic_server.dart
Replaced ctx.withResponse(...) with ctx.respond(...) in responders, static serving paths, middleware, and server error/headers paths; behavior unchanged.
Example
example/example.dart
Updated usage to ctx.respond(...).
Tests
test/middleware/routing_middleware_test.dart, test/static/test_util.dart, test/util/test_util.dart
Updated tests to use ctx.respond(...); assertions and outcomes unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • feat: Router middleware #68 — Prior work that introduced/used withResponse in Router middleware; directly affected by this rename to respond.
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nielsenko nielsenko self-assigned this Aug 28, 2025
@codecov

codecov Bot commented Aug 28, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.20%. Comparing base (e362193) to head (8341797).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #134   +/-   ##
=======================================
  Coverage   84.20%   84.20%           
=======================================
  Files          83       83           
  Lines        2716     2716           
  Branches     1480     1480           
=======================================
  Hits         2287     2287           
  Misses        429      429           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nielsenko nielsenko changed the title refactor: Rename withResponse to respond (matches connect/hijack) refactor: Rename withResponse to respond (matches connect/hijack) Aug 28, 2025
@nielsenko
nielsenko marked this pull request as ready for review August 28, 2025 09:47
@nielsenko

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 28, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
lib/src/handler/handler.dart (1)

61-65: Update docstring: references to withResponse are stale

Doc still says “for the withResponse call to succeed.” Should say respond.

Apply this minimal diff:

-/// `withResponse` call to succeed. The handler ensures the resulting context is
+/// `respond` call to succeed. The handler ensures the resulting context is
lib/src/adapter/context.dart (1)

41-41: Optional migration shim to ease external adopters off withResponse.

To reduce churn for downstreams, consider a deprecated extension that forwards withResponse(...) to respond(...).

Add in a small compat file (e.g., lib/src/adapter/respond_compat.dart):

// Temporary shim for migration; remove in next major.
extension RespondableContextWithResponseCompat on RespondableContext {
  @Deprecated('Use respond(Response) instead')
  ResponseContext withResponse(final Response r) => respond(r);
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8d5dbd9 and 444fe90.

📒 Files selected for processing (9)
  • example/example.dart (1 hunks)
  • lib/src/adapter/context.dart (4 hunks)
  • lib/src/handler/handler.dart (1 hunks)
  • lib/src/io/static/static_handler.dart (5 hunks)
  • lib/src/middleware/middleware.dart (1 hunks)
  • lib/src/relic_server.dart (2 hunks)
  • test/middleware/routing_middleware_test.dart (8 hunks)
  • test/static/test_util.dart (1 hunks)
  • test/util/test_util.dart (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: nielsenko
PR: serverpod/relic#76
File: lib/src/handler/handler.dart:20-20
Timestamp: 2025-05-23T04:15:01.420Z
Learning: In the relic codebase, ResponseContext is a subtype of HandledContext, making functions with signature ResponseContext Function(RequestContext) assignable to the Handler typedef (FutureOr<HandledContext> Function(NewContext ctx)) due to covariant return types and contravariant parameter types in Dart's type system.
📚 Learning: 2025-05-23T04:15:01.420Z
Learnt from: nielsenko
PR: serverpod/relic#76
File: lib/src/handler/handler.dart:20-20
Timestamp: 2025-05-23T04:15:01.420Z
Learning: In the relic codebase, ResponseContext is a subtype of HandledContext, making functions with signature ResponseContext Function(RequestContext) assignable to the Handler typedef (FutureOr<HandledContext> Function(NewContext ctx)) due to covariant return types and contravariant parameter types in Dart's type system.

Applied to files:

  • lib/src/middleware/middleware.dart
  • lib/src/handler/handler.dart
  • test/middleware/routing_middleware_test.dart
  • test/util/test_util.dart
  • lib/src/relic_server.dart
  • lib/src/adapter/context.dart
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Run Unit Tests (macos-latest, stable, downgrade)
  • GitHub Check: Run Unit Tests (macos-latest, 3.5.0, downgrade)
🔇 Additional comments (8)
example/example.dart (1)

33-35: LGTM: rename to ctx.respond is correct and preserves return type

The example aligns with the API change; returning ResponseContext remains valid for router usage (per covariant returns in this codebase).

test/static/test_util.dart (1)

46-51: LGTM: updated to ctx.respond

The not-found branch correctly uses the new respond API.

lib/src/handler/handler.dart (1)

66-68: LGTM: respondWith now uses ctx.respond

Functional behavior unchanged; naming is consistent with connect/hijack.

lib/src/middleware/middleware.dart (1)

56-70: LGTM: middleware paths updated to ctx/respond/respond

Early return, error path, and final post-processing all use respond; behavior preserved and types line up (ResponseContext implements respond).

test/util/test_util.dart (1)

27-33: LGTM: test helper now returns via ctx.respond

Sync helper continues to produce a ResponseContext; rename applied correctly.

test/middleware/routing_middleware_test.dart (1)

37-38: LGTM: tests updated to ctx.respond; type expectations still hold.

Return types remain ResponseContext, satisfying Handler’s FutureOr. No behavioral changes.

Also applies to: 60-61, 85-86, 124-125, 160-161, 225-226, 266-267, 309-309

lib/src/relic_server.dart (1)

124-132: LGTM: middleware now uses rc.respond/ctx.respond; semantics preserved.

Headers are augmented via copyWith + transform before responding; connect/hijack branches unchanged.

Also applies to: 141-143

lib/src/adapter/context.dart (1)

41-41: API rename solid and coherent with connect/hijack.

Interfaces and implementations now expose respond(Response); call sites remain type-safe (ResponseContext ⊂ HandledContext).

Also applies to: 56-57, 76-78, 97-99

Comment thread lib/src/adapter/context.dart Resolved
Comment thread lib/src/handler/handler.dart Resolved
Comment thread lib/src/io/static/static_handler.dart Resolved

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚀

@nielsenko
nielsenko merged commit aa9ac1d into serverpod:main Aug 28, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Oct 29, 2025
7 of 8 tasks
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