Documentation

Halt!

Updated
Browse documentation

Published 2026-08-13. V2 is a prerelease; the web core is release-gated and other previews are named separately. What beta means.

Read this page as HTML, Markdown, or structured JSON—or open the published Markdown with an AI assistant. Gemini receives the prompt through your clipboard because its signed-out page does not reliably prefill URL text; paste when the new tab opens. External assistants need the public site URL.

Halt!

halt! sets the current context body, plain-text content type, and status code. It is most useful in a before filter, where setting context content prevents the controller action from running.

File: src/controllers/admin_controller.cr — place the filter and action inside AdminController.

Crystal
class AdminController < ApplicationController
  before_action do
    only :index do
      halt!(403, "Forbidden") unless session[:admin_id]?
    end
  end

  def index
    render("index.ecr")
  end
end

halt! marks the request context; it does not raise an exception that escapes ordinary Crystal control flow. Inside an action, return an explicit response when later expressions must not run.

File: the controller that owns show, for example src/controllers/admin_controller.cr — replace that action body.

Crystal
def show
  unless authorized?
    return set_response(
      body: "Forbidden",
      status_code: 403,
      content_type: "text/plain"
    )
  end

  render("show.ecr")
end

Amber's redirect helper sets the Location header and uses the same context response mechanism.

File: a controller action under src/controllers/ — return this expression at the point where request processing should redirect.

Crystal
redirect_to location: "/login", status: 302

The V1 Slang example and its claim that halt! interrupts any action like an exception are not copied into V2.