class
Orion::Server::Context
- Orion::Server::Context
- HTTP::Server::Context
- Reference
- Object
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.crorion/server/context_helpers.cr
Instance Method Summary
-
#bad_request!(message = "Bad Request", json = nil)
4xx Client Errors
- #config : Orion::Config::ReadOnly | Nil
- #config=(config : Orion::Config::ReadOnly)
- #config? : Orion::Config::ReadOnly | Nil | Nil
- #conflict!(message = "Conflict", json = nil)
- #created!(message = nil, json = nil, location : String | Nil = nil)
- #csrf_token : String | Nil
- #csrf_token=(csrf_token : String | Nil)
-
#flash : Orion::Middleware::Flash
Get flash with safe access
- #flash=(flash : Orion::Middleware::Flash | Nil)
- #forbidden!(message = "Forbidden", json = nil)
- #found!(location : String)
-
#halt(status : Int32, message : String | Nil = nil)
Halt processing
- #head(status : Int32 | Symbol)
-
#json(data, status : Int32 = 200)
Render JSON response
- #json_accepted(data)
- #json_bad_request(data)
- #json_created(data)
- #json_forbidden(data)
- #json_not_found(data)
-
#json_ok(data)
JSON with specific statuses
- #json_server_error(data)
- #json_unauthorized(data)
- #json_unprocessable(data)
- #moved!(location : String)
- #no_content!
- #not_found!(message = "Not Found", json = nil)
-
#ok!(message : String | Nil = nil)
2xx Success
-
#params : ParamHash
Unified parameter access (path_params + query_params) Shorthand for accessing params without going through request
-
#path_params : Hash(String, String)
Shorthand for path parameters
-
#query_params : HTTP::Params
Shorthand for query parameters
-
#redirect!(location : String, status : Int32 = 302)
3xx Redirects
-
#render_html(html : String, status : Int32 = 200)
Render HTML response
-
#render_text(text : String, status : Int32 = 200)
Render text response
-
#request : Request
The
HTTP::Requestto process. -
#response : Response
The
HTTP::Server::Responseto configure and write to. -
#server_error!(message = "Internal Server Error", json = nil)
5xx Server Errors
- #service_unavailable!(message = "Service Unavailable", retry_after : Int32 | Nil = nil)
-
#session : Orion::Middleware::SessionStore
Get session with safe access
- #session=(session : Orion::Middleware::SessionStore | Nil)
-
#status(code : Int32)
Generic status
- #too_many_requests!(message = "Too Many Requests", retry_after : Int32 | Nil = nil)
- #unauthorized!(message = "Unauthorized", json = nil)
- #unprocessable!(message = "Unprocessable Entity", json = nil)
Instance Method Detail
Unified parameter access (path_params + query_params) Shorthand for accessing params without going through request
The HTTP::Server::Response to configure and write to.