hanami / api

Minimal, lightweight, fastest Ruby framework for HTTP APIs.
https://hanamirb.org
MIT License
350 stars 13 forks source link

Shared Logic for block contexts #25

Closed anuj1102 closed 3 years ago

anuj1102 commented 3 years ago

I'm really enjoying hanami/api so far. Is there a way to have shared logic between block contexts? I know I can write my own rack endpoint but I don't want to lose the block context apis, and my shared logic is pretty small at the moment. If not, is there a recommended approach?

Ex:

def my_shared_logic
   halt 401 unless authorized?
end

get "/" do
  my_shared_logic
  "Hello, world"
end

get "/" do
   my_shared_logic
  "Hello, world"
end
jodosha commented 3 years ago

@anuj1102 Could you please try #26 and tell me if that works for you? Thanks 🙂

anuj1102 commented 3 years ago

Just tested this out, it's exactly what I needed!! Thank you for the quick response.