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


[View source]
def config : Orion::Config::ReadOnly | Nil #

[View source]
def config=(config : Orion::Config::ReadOnly) #

[View source]
def config? : Orion::Config::ReadOnly | Nil | Nil #

[View source]
def conflict!(message = "Conflict", json = nil) #

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

[View source]
def csrf_token : String | Nil #

[View source]
def csrf_token=(csrf_token : String | Nil) #

[View source]

Get flash with safe access


[View source]
def flash=(flash : Orion::Middleware::Flash | Nil) #

[View source]
def forbidden!(message = "Forbidden", json = nil) #

[View source]
def found!(location : String) #

[View source]
def halt(status : Int32, message : String | Nil = nil) #

Halt processing


[View source]
def head(status : Int32 | Symbol) #

[View source]
def json(data, status : Int32 = 200) #

Render JSON response


[View source]
def json_accepted(data) #

[View source]
def json_bad_request(data) #

[View source]
def json_created(data) #

[View source]
def json_forbidden(data) #

[View source]
def json_not_found(data) #

[View source]
def json_ok(data) #

JSON with specific statuses


[View source]
def json_server_error(data) #

[View source]
def json_unauthorized(data) #

[View source]
def json_unprocessable(data) #

[View source]
def moved!(location : String) #

[View source]
def no_content! #

[View source]
def not_found!(message = "Not Found", json = nil) #

[View source]
def ok!(message : String | Nil = nil) #

2xx Success


[View source]
def params : ParamHash #

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


[View source]
def path_params : Hash(String, String) #

Shorthand for path parameters


[View source]
def query_params : HTTP::Params #

Shorthand for query parameters


[View source]
def redirect!(location : String, status : Int32 = 302) #

3xx Redirects


[View source]
def render_html(html : String, status : Int32 = 200) #

Render HTML response


[View source]
def render_text(text : String, status : Int32 = 200) #

Render text response


[View source]
def request : Request #
Description copied from class HTTP::Server::Context

The HTTP::Request to process.


[View source]
def response : Response #
Description copied from class HTTP::Server::Context

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


[View source]
def server_error!(message = "Internal Server Error", json = nil) #

5xx Server Errors


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

[View source]

Get session with safe access


[View source]
def session=(session : Orion::Middleware::SessionStore | Nil) #

[View source]
def status(code : Int32) #

Generic status


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

[View source]
def unauthorized!(message = "Unauthorized", json = nil) #

[View source]
def unprocessable!(message = "Unprocessable Entity", json = nil) #

[View source]