Core
The core API provides the fundamental building blocks for Azu applications, including endpoints, requests, responses, and the main application class.
Azu::Application
The main application class that orchestrates your Azu web application.
Methods
start(middleware : Array(Azu::Handler::Base) = [] of Azu::Handler::Base)
start(middleware : Array(Azu::Handler::Base) = [] of Azu::Handler::Base)Starts the Azu application with the specified middleware stack.
# Start with default middleware
Azu.start
# Start with custom middleware
Azu.start [
Azu::Handler::Rescuer.new,
Azu::Handler::Logger.new,
Azu::Handler::CORS.new,
Azu::Handler::Static.new
]stop
stopGracefully stops the application.
Azu::Endpoint
Base class for all HTTP endpoints in Azu.
Methods
get(path : String)
get(path : String)post(path : String)
post(path : String)put(path : String)
put(path : String)patch(path : String)
patch(path : String)delete(path : String)
delete(path : String)Define HTTP routes for the endpoint.
call
callThe main method that handles the HTTP request. Must be implemented by each endpoint.
Azu::Request
Represents an HTTP request with type-safe parameter access.
Properties
params- Hash of route parametersquery- Hash of query parametersbody- Request body contentheaders- HTTP headersmethod- HTTP methodpath- Request path
Request Methods
param(key : String) : String
param(key : String) : StringGet a route parameter by key.
query(key : String) : String?
query(key : String) : String?Get a query parameter by key.
header(key : String) : String?
header(key : String) : String?Get an HTTP header by key.
Azu::Response
Base class for all HTTP responses in Azu.
Response Methods
status(code : Int32)
status(code : Int32)Set the HTTP status code.
header(key : String, value : String)
header(key : String, value : String)Set an HTTP header.
body(content : String)
body(content : String)Set the response body.
Azu::Router
Handles HTTP routing in Azu applications.
Router Methods
add_route(method : String, path : String, handler : Azu::Endpoint)
add_route(method : String, path : String, handler : Azu::Endpoint)Add a route to the router.
route(method : String, path : String) : Azu::Endpoint?
route(method : String, path : String) : Azu::Endpoint?Find a route handler for the given method and path.
Azu::Component
Base class for real-time components in Azu.
Component Methods
content
contentGenerate the component's HTML content.
on_event(name : String, data : Hash(String, String))
on_event(name : String, data : Hash(String, String))Handle client-side events.
Azu::Channel
Base class for WebSocket channels in Azu.
Channel Methods
on_connect
on_connectCalled when a client connects to the channel.
on_message(message : String)
on_message(message : String)Called when a message is received from the client.
on_disconnect
on_disconnectCalled when a client disconnects from the channel.
Azu::Configuration
Configuration management for Azu applications.
Configuration Properties
port- Server port (default: 3000)host- Server host (default: "0.0.0.0")environment- Application environmentdebug- Debug mode flag
Configuration Methods
configure(&block)
configure(&block)Configure the application.
Azu::Environment
Environment detection and configuration.
Environment Methods
development? : Bool
development? : BoolCheck if running in development mode.
production? : Bool
production? : BoolCheck if running in production mode.
Azu::Cache
Caching system for Azu applications.
Cache Methods
get(key : String) : String?
get(key : String) : String?Get a value from the cache.
set(key : String, value : String, ttl : Time::Span? = nil)
set(key : String, value : String, ttl : Time::Span? = nil)Set a value in the cache.
delete(key : String)
delete(key : String)Delete a value from the cache.
Azu::Templates
Template rendering system for Azu applications.
Template Methods
render(template : String, context : Hash(String, String) = {} of String => String) : String
render(template : String, context : Hash(String, String) = {} of String => String) : StringRender a template with the given context.
register_template(name : String, content : String)
register_template(name : String, content : String)Register a template.
Error Handling
Azu provides comprehensive error handling through the Azu::Response::Error class.
Azu::Response::Error
Base class for all Azu errors.
Error Response
Error responses automatically set appropriate HTTP status codes and provide error details.
Performance Monitoring
Azu includes built-in performance monitoring for components and endpoints.
Component Performance
Components automatically track rendering time and memory usage.
Endpoint Performance
Endpoints can be monitored for response times and resource usage.
Next Steps
Learn about Request Validation
Explore Template Rendering
Understand WebSocket Channels
See Component System
Last updated
Was this helpful?
