ruby-grape / ruby-grape/grape

`halt` for instantly returning a response, interrupting current handler execution

Open
#2,374 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discuss! feature request
Dominant language
Ruby
Stars
10k
Forks
1.2k
Avg merge
14h 38m
Merged PRs (30d)
92

Description

Hey 👋

Do you think a halt method can be interesting for instantly returning a response, interrupting current handler execution? An alternative to error! ?

Something like:

class MyAPI < Grape::API
  get '/wadus' do
    halt 401 unless authenticated?
  end
end

I think it can be useful and it's a standard. Also, it's present in some many other frameworks:

https://github.com/alisnic/nyny#request-scope
https://github.com/jeremyevans/roda/blob/master/lib/roda/plugins/halt.rb
https://github.com/hanami/controller#throwable-http-statuses

Thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no repository files or tests; start by comparing the linked halt implementations with Grape's existing error! behavior. Clarify the intended interruption and response semantics before locating the relevant Grape entry points; done means the behavior is agreed and covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.