The Azu module is the main entry point for creating Azu applications.
module MyApp
include Azu
endConfigure 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| 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 |
enum Environment
Development
Test
Production
endif Azu.env.production?
# Production-only code
end
Azu.env.development? # => Bool
Azu.env.test? # => BoolStart 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 with a block for additional setup.
MyApp.start do |server|
server.bind_tcp("0.0.0.0", 8080)
server.listen
endAccess the configured cache store.
Azu.cache.set("key", "value", expires_in: 1.hour)
Azu.cache.get("key") # => "value"
Azu.cache.delete("key")Access the application router.
Azu.router.routes # => Array of registered routesAccess the application logger.
Azu.log.info { "Application started" }
Azu.log.error(exception: ex) { "Error occurred" }alias EmptyRequest = Azu::Request::Empty
alias Params = Hash(String, String)VERSION = "0.5.28"