module Onyx

Overview

Powerful framework for modern applications. See onyxframework.org.

Defined in:

onyx.cr
onyx/logger.cr
onyx/db.cr
lib/onyx-eda/src/onyx-eda.cr
onyx/eda.cr
lib/onyx-http/src/onyx-http.cr
onyx/http.cr
onyx/sql.cr

Class Method Summary

Macro Summary

Class Method Detail

def self.channel : Onyx::EDA::Channel #

Top-level Onyx::EDA::Channel instance. It's in-memory by default. To change the channel type, use Onyx.channel(type) macro.


[View source]
def self.channel=(channel : Onyx::EDA::Channel) #

Top-level Onyx::EDA::Channel instance. It's in-memory by default. To change the channel type, use Onyx.channel(type) macro.


[View source]
def self.db : DB::Database #

Top-level DB::Database instance. requires DATABASE_URL environment variable to be set. It will validate the connection on program run with Onyx.db.scalar("SELECT 1") call, raising of failure.


[View source]
def self.db=(db : DB::Database) #

Top-level DB::Database instance. requires DATABASE_URL environment variable to be set. It will validate the connection on program run with Onyx.db.scalar("SELECT 1") call, raising of failure.


[View source]
def self.delete(*args, **nargs) #

Define a DELETE route for the top-level .router. See HTTP::Router#delete.


[View source]
def self.delete(*args, **nargs, &block : HTTP::Server::Context -> Nil) #

Define a DELETE route with block for the top-level .router. See HTTP::Router#delete.


[View source]
def self.draw(&block) #

Draw routes for the top-level .router. See HTTP::Router#draw.


[View source]
def self.emit(*args, **nargs) #

Call Onyx::EDA::Channel#emit on the .channel.


[View source]
def self.exec(*args, **nargs) #

Call Onyx::SQL::Repository#exec on the top-level .repo instance.


[View source]
def self.get(*args, **nargs, &block : HTTP::Server::Context -> Nil) #

Define a GET route with block for the top-level .router. See HTTP::Router#get.


[View source]
def self.get(*args, **nargs) #

Define a GET route for the top-level .router. See HTTP::Router#get.


[View source]
def self.logger : Logger #

The top-level Logger instance. Has a custom slim formatter and level depending on CRYSTAL_ENV environment variable:

  • "production" -- INFO
  • all other (including nil) -- DEBUG
require "onyx/logger"
Onyx.logger.debug("Hello world!")
# DEBUG [12:45:52.520 #13543] Hello world!

[View source]
def self.logger=(logger : Logger) #

The top-level Logger instance. Has a custom slim formatter and level depending on CRYSTAL_ENV environment variable:

  • "production" -- INFO
  • all other (including nil) -- DEBUG
require "onyx/logger"
Onyx.logger.debug("Hello world!")
# DEBUG [12:45:52.520 #13543] Hello world!

[View source]
def self.options(*args, **nargs) #

Define a OPTIONS route for the top-level .router. See HTTP::Router#options.


[View source]
def self.options(*args, **nargs, &block : HTTP::Server::Context -> Nil) #

Define a OPTIONS route with block for the top-level .router. See HTTP::Router#options.


[View source]
def self.patch(*args, **nargs) #

Define a PATCH route for the top-level .router. See HTTP::Router#patch.


[View source]
def self.patch(*args, **nargs, &block : HTTP::Server::Context -> Nil) #

Define a PATCH route with block for the top-level .router. See HTTP::Router#patch.


[View source]
def self.post(*args, **nargs) #

Define a POST route for the top-level .router. See HTTP::Router#post.


[View source]
def self.post(*args, **nargs, &block : HTTP::Server::Context -> Nil) #

Define a POST route with block for the top-level .router. See HTTP::Router#post.


[View source]
def self.put(*args, **nargs) #

Define a PUT route for the top-level .router. See HTTP::Router#put.


[View source]
def self.put(*args, **nargs, &block : HTTP::Server::Context -> Nil) #

Define a PUT route with block for the top-level .router. See HTTP::Router#put.


[View source]
def self.query(*args, **nargs) #

Call Onyx::SQL::Repository#query on the top-level .repo instance.


[View source]
def self.renderer #

[View source]
def self.renderer=(value) #

[View source]
def self.repo : Onyx::SQL::Repository #

Top-level Onyx::SQL::Repository instance. Has Onyx.db as a db and and Onyx.logger as a logger.


[View source]
def self.repo=(repo : Onyx::SQL::Repository) #

Top-level Onyx::SQL::Repository instance. Has Onyx.db as a db and and Onyx.logger as a logger.


[View source]
def self.router #

The top-level HTTP::Router instance.


[View source]
def self.scalar(*args, **nargs) #

Call Onyx::SQL::Repository#scalar on the top-level .repo instance.


[View source]
def self.subscribe(object, event : T.class, &proc : T -> Nil) forall T #

Call Onyx::EDA::Channel#subscribe on the .channel.


[View source]
def self.unsubscribe(*args, **nargs) #

Call Onyx::EDA::Channel#unsubscribe on the .channel.


[View source]
def self.unsubscribe(object, event : T.class, &proc : T -> Nil) forall T #

Call Onyx::EDA::Channel#unsubscribe on the .channel.


[View source]
def self.ws(*args, **nargs) #

Define a "ws://" route with block for the top-level .router. See HTTP::Router#ws.


[View source]
def self.ws(*args, **nargs, &block : ::HTTP::WebSocket, HTTP::Server::Context -> Nil) #

Define a "ws://" route with block for the top-level .router. See HTTP::Router#ws.


[View source]

Macro Detail

macro channel(type) #

Change the Onyx.channel type. The only valid value is redis.

NOTE It must be called before any event is declared.

require "onyx/eda"

Onyx.channel(:redis)

struct MyEvent
  include Onyx::EDA::Event
end

# ...

[View source]
macro listen(host = "127.0.0.1", port = 5000, reuse_port = false, **handler_options, &block) #

Instantiate an Onyx::HTTP::Server, bind it to the host and port and start listening. Routes for it are defined with top-level Onyx.get methods and its siblings.

You can insert your custom code into the &block. At this point, handlers variable will be available.


[View source]
macro render(io, path) #

Render a template at path into io with Kilt.

Onyx.render(env.response, "./hello.html.ecr")
# Expands to
Kilt.embed("./hello.html.ecr", env.response)

[View source]