module Orion::DSL::Scope

Overview

Scopes are a method in which you can nest routes under a common path. This prevents the need for duplicating paths and allows a developer to easily change the parent of a set of child paths.

router MyApplicationRouter do
  scope "users" do
    root to: "Users#index"
    get ":id", to: "Users#show"
    delete ":id", to: "Users#destroy"
  end
end

Handlers within nested routes

Instances of link:https://crystal-lang.org/api/HTTP/Handler.html[HTTP::Handler] can be used within a scope block and will only apply to the subsequent routes within that scope. It is important to note that the parent context's handlers will also be used.

Handlers will only apply to the routes specified below them, so be sure to place your handlers near the top of your scope.

router MyApplicationRouter do
  scope "users" do
    use AuthorizationHandler.new
    root to: "Users#index"
    get ":id", to: "Users#show"
    delete ":id", to: "Users#destroy"
  end
end

Defined in:

orion/dsl/scope.cr

Macro Summary

Macro Detail

macro scope(path = nil, helper_prefix = nil, controller = nil) #

Create a scope, optionall nested under a path.


[View source]