Skip to content

halt for instantly returning a response, interrupting current handler execution #2374

Open
@jcagarcia

Description

@jcagarcia

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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions