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)

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

Gracefully stops the application.

Azu::Endpoint

Base class for all HTTP endpoints in Azu.

Methods

get(path : String)

post(path : String)

put(path : String)

patch(path : String)

delete(path : String)

Define HTTP routes for the endpoint.

call

The 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 parameters

  • query - Hash of query parameters

  • body - Request body content

  • headers - HTTP headers

  • method - HTTP method

  • path - Request path

Request Methods

param(key : String) : String

Get a route parameter by key.

query(key : String) : String?

Get a query parameter by key.

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)

Set the HTTP status code.

header(key : String, value : String)

Set an HTTP header.

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 a route to the router.

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

Generate the component's HTML content.

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

Called when a client connects to the channel.

on_message(message : String)

Called when a message is received from the client.

on_disconnect

Called 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 environment

  • debug - Debug mode flag

Configuration Methods

configure(&block)

Configure the application.

Azu::Environment

Environment detection and configuration.

Environment Methods

development? : Bool

Check if running in development mode.

production? : Bool

Check if running in production mode.

Azu::Cache

Caching system for Azu applications.

Cache Methods

get(key : String) : String?

Get a value from the cache.

set(key : String, value : String, ttl : Time::Span? = nil)

Set a value in the cache.

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 a template with the given context.

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

Last updated

Was this helpful?