Class: NuHttp::App

Inherits:
Object
  • Object
show all
Defined in:
lib/nuhttp/app.rb

Instance Method Summary collapse

Constructor Details

#initialize(router) ⇒ App

Returns a new instance of App.



6
7
8
# File 'lib/nuhttp/app.rb', line 6

def initialize(router)
  @router = router
end

Instance Method Details

#dispatch(req) ⇒ Object

The entrypoint of the request.



12
13
14
15
16
17
18
19
20
# File 'lib/nuhttp/app.rb', line 12

def dispatch(req)
  route, params = @router.resolve(req)
  # Create a new Context
  ctx = Context.new(req:, route:)
  # Populate req.params
  req.params = params
  route.handler.call(ctx)
  ctx.res
end

#routesObject



22
23
24
# File 'lib/nuhttp/app.rb', line 22

def routes
  @router.routes
end