Getting Started

Welcome to Azu! This tutorial will guide you through installing Crystal and Azu, then building your first working application.

What You'll Learn

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

Prerequisites

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)

Step 1: Install Crystal

Azu requires Crystal 0.35.0 or higher. Install Crystal for your operating system:

macOS

Linux (Ubuntu/Debian)

Linux (Fedora/CentOS/RHEL)

Windows

Step 2: Create Your Project

Create a new Crystal project and add Azu as a dependency:

Edit your shard.yml to add Azu:

Install dependencies:

Step 3: Create Your First Application

Replace the contents of src/my_first_azu_app.cr with:

Step 4: Run Your Application

Start the server:

You should see output like:

Step 5: Test Your Endpoints

Open a new terminal and test your endpoints:

You can also open http://localhost:4000/ in your browser.

Understanding the Code

Let's break down what you just created:

Application Module

This defines your application and configures the server settings.

Endpoints

Endpoints handle HTTP requests:

  • include Azu::Endpoint(RequestType, ResponseType) defines the contract

  • get "/" declares the HTTP method and route

  • def call contains your handler logic

Route Parameters

The :name in the route captures that segment and makes it available via params.

Project Structure

Your project should now look like this:

Troubleshooting

"command not found: crystal"

Add Crystal to your PATH:

"Error resolving dependencies"

Clear the cache and reinstall:

Port already in use

Change the port in your configuration or kill the existing process:

Next Steps

Congratulations! You've created your first Azu application. Continue learning with:


Your Azu journey begins! You now have a working development environment and understand the basics of creating endpoints.

Last updated

Was this helpful?