Router
Namespaces allow parameter definitions and apply to every method within the namespace.
Its method has a number of aliases, including: group
resource
resources
and segment
. Use whichever reads the best for your API.
namespace :statuses do
namespace ":user_id" do
desc "Retrieve a user's status."
params do
requires :status_id, type: Integer
end
get ":status_id" do
params[:user_id] |> IO.inspect
params[:status_id] |> IO.inspect
end
end
end
You can conveniently define a route parameter as a namespace using route_param
.
namespace :statuses do
route_param :id, type: String do
desc "Returns all replies for a status."
get :replies do
params[:id] |> IO.inspect
end
desc "Returns a status."
get do
params[:id] |> IO.inspect
end
end
end
Updated less than a minute ago