class Orion::Server::Context

Overview

Context Helpers - Convenience methods on Server::Context Makes all helpers easily discoverable via context parameter

Usage: get "/users/:id" do |ctx| user = User.find?(ctx.params["id"]) ctx.not_found! unless user ctx.json(user.to_h) end

Defined in:

orion/server/context.cr
orion/server/context_helpers.cr

Instance Method Summary

Instance Method Detail

def bad_request!(message = "Bad Request", json = nil) #

4xx Client Errors


def config : Orion::Config::ReadOnly | Nil #

def config=(config : Orion::Config::ReadOnly) #

def config? : Orion::Config::ReadOnly | Nil | Nil #

def conflict!(message = "Conflict", json = nil) #

def created!(message = nil, json = nil, location : String | Nil = nil) #

def csrf_token : String | Nil #

def csrf_token=(csrf_token : String | Nil) #

Get flash with safe access


def flash=(flash : Orion::Middleware::Flash | Nil) #

def forbidden!(message = "Forbidden", json = nil) #

def found!(location : String) #

def halt(status : Int32, message : String | Nil = nil) #

Halt processing


def head(status : Int32 | Symbol) #

def json(data, status : Int32 = 200) #

Render JSON response


def json_accepted(data) #

def json_bad_request(data) #

def json_created(data) #

def json_forbidden(data) #

def json_not_found(data) #

def json_ok(data) #

JSON with specific statuses


def json_server_error(data) #

def json_unauthorized(data) #

def json_unprocessable(data) #

def moved!(location : String) #

def no_content! #

def not_found!(message = "Not Found", json = nil) #

def ok!(message : String | Nil = nil) #

2xx Success


def params : ParamHash #

Unified parameter access (path_params + query_params) Shorthand for accessing params without going through request


def path_params : Hash(String, String) #

Shorthand for path parameters


def query_params : HTTP::Params #

Shorthand for query parameters


def redirect!(location : String, status : Int32 = 302) #

3xx Redirects


def render_html(html : String, status : Int32 = 200) #

Render HTML response


def render_text(text : String, status : Int32 = 200) #

Render text response


def request : Request #
Description copied from class HTTP::Server::Context

The HTTP::Request to process.


def response : Response #
Description copied from class HTTP::Server::Context

The HTTP::Server::Response to configure and write to.


def server_error!(message = "Internal Server Error", json = nil) #

5xx Server Errors


def service_unavailable!(message = "Service Unavailable", retry_after : Int32 | Nil = nil) #

Get session with safe access


def session=(session : Orion::Middleware::SessionStore | Nil) #

def status(code : Int32) #

Generic status


def too_many_requests!(message = "Too Many Requests", retry_after : Int32 | Nil = nil) #

def unauthorized!(message = "Unauthorized", json = nil) #

def unprocessable!(message = "Unprocessable Entity", json = nil) #