refactor sinatra http method invocation code