Skip to content

Simplify endpoint block execution and deprecate return call in it #2577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ericproulx
Copy link
Contributor

@ericproulx ericproulx commented Jul 2, 2025

Deprecate Endpoint Return Value

Summary

This PR simplifies endpoint's block execution. It was relying on an unbound method but it always been re-binded to endpoint instance. Instead, I just call instance_exec from the endpoint instance. First, we deprecate and next version we will remove the rescue LocalJumpError.

Motivation

  • I don't know why we want to use return in an endpoint. Seems to be an old thing.
  • generate_api_method was generating a couple of strings that were retained in memory. I've seen it in grape-on-rack.

Changes

  • Marked the return value of Grape::Endpoint#call as deprecated in the documentation and code comments.
  • Added deprecation warnings where appropriate.
  • Updated relevant specs and documentation.
  • Its a lamba instead of Proc to be able to capture the LocalJumpError and return its exit_value for not breaking anything.

Impact

  • No breaking changes for typical API usage.
  • Users who were relying on the return value of Grape::Endpoint#call should update their code to avoid this pattern.

Checklist

  • Deprecation warning added
  • Documentation updated
  • Specs updated

@ericproulx ericproulx requested a review from dblock July 2, 2025 21:33
@ericproulx ericproulx force-pushed the deprecated_endpoint_return branch from 1076e6d to ea27c2d Compare July 2, 2025 21:35
@ericproulx ericproulx marked this pull request as ready for review July 2, 2025 21:39
@ericproulx ericproulx force-pushed the deprecated_endpoint_return branch from 3b56984 to 6f49321 Compare July 2, 2025 21:47
@ericproulx ericproulx force-pushed the deprecated_endpoint_return branch from 6f49321 to f6aebfa Compare July 2, 2025 21:48
@@ -3,6 +3,10 @@ Upgrading Grape

### Upgrading to >= 3.0.0

### Endpoint execution simplified and `return` deprecated

Executing a endpoint's block has been simplified and calling `return` in it has been deprecated.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Executing a endpoint's block has been simplified and calling `return` in it has been deprecated.
Executing a endpoint's block has been simplified and calling `return` in it has been deprecated.
See [#2577](https://github.com/ruby-grape/grape/pull/2577) for more information.

@dblock
Copy link
Member

dblock commented Jul 5, 2025

Feel free to merge with the UPGRADING update @ericproulx.

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