Method: Hanami::API.scope

Defined in:
lib/hanami/api.rb

.scopeObject

Defines a routing scope. Routes defined in the context of a scope, inherit the given path as path prefix and as a named routes prefix.

Examples:

require "hanami/api"

class MyAPI < Hanami::API
  scope "v1" do
    get "/users", to: ->(*) { ... }, as: :users
  end
end

# It generates a route with a path `/v1/users`

Parameters:

  • path (String)

    the scope path to be used as a path prefix

  • blk (Proc)

    the routes definitions withing the scope

See Also:

Since:

  • 0.1.0



293
294
295
# File 'lib/hanami/api.rb', line 293

def self.scope(...)
  @router.scope(...)
end