hobbit-contrib icon indicating copy to clipboard operation
hobbit-contrib copied to clipboard

string path as first argument in filter isn't enough

Open wafcio opened this issue 10 years ago • 1 comments

We can create the same path in different HTTP request type. For example:

GET /posts/:id PUT /posts/:id

when we add before('/posts/:id') { ... } before filter will be work for both routes.

wafcio avatar Jul 21 '14 17:07 wafcio

Hi @wafcio, I know it's not possible to add filter for specific request methods, and that's because I wanted the filters to be sinatra compatible. You have 2 options:

  • Ask for the request method inside the filter:
before '/' do
  if request.get?
    # do something
  end
end
  • Create your own hobbit extension. If you do so, we can start growing the hobbit ecosystem and that's great

patriciomacadden avatar Jul 21 '14 19:07 patriciomacadden