Welcome to Azu! This tutorial will guide you through installing Crystal and Azu, then building your first working application.
By the end of this tutorial, you will have:
- Crystal and Azu installed on your system
- A working Azu application running locally
- Understanding of the basic project structure
Before starting, ensure you have:
- A computer running macOS, Linux, or Windows
- Internet connection for downloading dependencies
- A terminal/command line application
- A code editor (VS Code recommended)
Azu requires Crystal 0.35.0 or higher. Install Crystal for your operating system:
# Using Homebrew (recommended)
brew install crystal-lang
# Verify installation
crystal version
# Should output: Crystal 1.x.x# Add Crystal repository
curl -fsSL https://crystal-lang.org/install.sh | sudo bash
# Install Crystal
sudo apt-get install crystal
# Verify installation
crystal version# Add Crystal repository
curl -fsSL https://crystal-lang.org/install.sh | sudo bash
# Fedora
sudo dnf install crystal
# CentOS/RHEL
sudo yum install crystal
# Verify installation
crystal version# Using Chocolatey
choco install crystal
# Using Scoop
scoop install crystal
# Verify installation
crystal versionCreate a new Crystal project and add Azu as a dependency:
# Create project directory
crystal init app my_first_azu_app
cd my_first_azu_appEdit your shard.yml to add Azu:
name: my_first_azu_app
version: 0.1.0
authors:
- Your Name <you@example.com>
dependencies:
azu:
github: azutoolkit/azu
version: ~> 0.5.28
crystal: >= 0.35.0
license: MITInstall dependencies:
shards installReplace the contents of src/my_first_azu_app.cr with:
require "azu"
# Define your application module
module MyFirstAzuApp
include Azu
configure do
port = 4000
host = "0.0.0.0"
end
end
# Create a simple endpoint
struct HelloEndpoint
include Azu::Endpoint(EmptyRequest, Azu::Response::Text)
get "/"
def call
text "Hello from Azu!"
end
end
# Create a JSON endpoint
struct GreetEndpoint
include Azu::Endpoint(EmptyRequest, Azu::Response::Json)
get "/greet/:name"
def call
json({
message: "Hello, #{params["name"]}!",
timestamp: Time.utc.to_rfc3339
})
end
end
# Start the server
MyFirstAzuApp.start [
HelloEndpoint.new,
GreetEndpoint.new,
]Start the server:
crystal run src/my_first_azu_app.crYou should see output like:
Server started at Fri 01/24/2026 10:30:45.
⤑ Environment: development
⤑ Host: 0.0.0.0
⤑ Port: 4000
⤑ Startup Time: 12.34 millis
Open a new terminal and test your endpoints:
# Test the hello endpoint
curl http://localhost:4000/
# Output: Hello from Azu!
# Test the greet endpoint
curl http://localhost:4000/greet/World
# Output: {"message":"Hello, World!","timestamp":"2026-01-24T10:30:45Z"}You can also open http://localhost:4000/ in your browser.
Let's break down what you just created:
module MyFirstAzuApp
include Azu
configure do
port = 4000
host = "0.0.0.0"
end
endThis defines your application and configures the server settings.
struct HelloEndpoint
include Azu::Endpoint(EmptyRequest, Azu::Response::Text)
get "/"
def call
text "Hello from Azu!"
end
endEndpoints handle HTTP requests:
include Azu::Endpoint(RequestType, ResponseType)defines the contractget "/"declares the HTTP method and routedef callcontains your handler logic
get "/greet/:name"
def call
params["name"] # Access route parameters
endThe :name in the route captures that segment and makes it available via params.
Your project should now look like this:
my_first_azu_app/
├── shard.yml # Dependencies
├── shard.lock # Locked versions
├── src/
│ └── my_first_azu_app.cr # Main application
├── lib/ # Installed dependencies
└── spec/ # Test files
Add Crystal to your PATH:
export PATH="/usr/local/bin:$PATH"
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrcClear the cache and reinstall:
rm -rf lib/ shard.lock
shards installChange the port in your configuration or kill the existing process:
lsof -i :4000
kill -9 <PID>Congratulations! You've created your first Azu application. Continue learning with:
- Building a User API - Create a complete CRUD API
- Adding WebSockets - Add real-time features
- Working with Databases - Connect to PostgreSQL or MySQL
Your Azu journey begins! You now have a working development environment and understand the basics of creating endpoints.