Skip to content

Latest commit

 

History

History
138 lines (98 loc) · 2.25 KB

File metadata and controls

138 lines (98 loc) · 2.25 KB

Core Module Reference

The Azu module is the main entry point for creating Azu applications.

Including Azu

module MyApp
  include Azu
end

Configuration

configure

Configure application settings.

Azu.configure do |config|
  config.port = 8080
  config.host = "0.0.0.0"
  config.env = Environment::Production
  config.template_hot_reload = false
end

Configuration Options

Option Type Default Description
port Int32 4000 HTTP server port
host String "0.0.0.0" Bind address
env Environment Development Environment mode
template_hot_reload Bool true Reload templates on change
log Log::Severity Debug Log level
cache Cache::Store MemoryStore Cache backend

Environment

enum Environment
  Development
  Test
  Production
end

Checking Environment

if Azu.env.production?
  # Production-only code
end

Azu.env.development?  # => Bool
Azu.env.test?         # => Bool

Starting the Application

start

Start the HTTP server with handlers.

MyApp.start [
  Azu::Handler::Rescuer.new,
  Azu::Handler::Logger.new,
  MyEndpoint.new,
]

Parameters:

  • handlers : Array(HTTP::Handler) - Handler chain

start (block)

Start with a block for additional setup.

MyApp.start do |server|
  server.bind_tcp("0.0.0.0", 8080)
  server.listen
end

Cache Access

cache

Access the configured cache store.

Azu.cache.set("key", "value", expires_in: 1.hour)
Azu.cache.get("key")  # => "value"
Azu.cache.delete("key")

Router Access

router

Access the application router.

Azu.router.routes  # => Array of registered routes

Logging

log

Access the application logger.

Azu.log.info { "Application started" }
Azu.log.error(exception: ex) { "Error occurred" }

Type Aliases

alias EmptyRequest = Azu::Request::Empty
alias Params = Hash(String, String)

Constants

VERSION = "0.5.28"

See Also