Learn CRYSTAL with Real Code Examples
Updated Nov 20, 2025
Practical Examples
CLI tool parsing arguments
REST API backend
Concurrent web crawler
JSON data processor
Simple microservice with fiber-based concurrency
Troubleshooting
Check type mismatches reported by compiler
Verify Shards dependencies
Use `--error-trace` for detailed compilation errors
Ensure correct Crystal version
Debug runtime exceptions with logging
Testing Guide
Use built-in `Spec` module
Write unit tests in `spec/` directory
Run `crystal spec`
Test concurrency edge cases
Use mocks and fixtures for IO testing
Deployment Options
Deploy compiled binaries directly
Containerized deployment (Docker)
Serverless functions with native binary
Package CLI tools for distribution
Cloud deployment for web backends
Tools Ecosystem
Crystal compiler
Shards dependency manager
Kemal web framework
Amber web framework
crystal tool for testing & formatting
Integrations
HTTP servers and REST APIs
Database libraries (PostgreSQL, SQLite, MySQL)
JSON/XML processing
CLI tools integration
Interfacing with C libraries via `lib`
Productivity Tips
Leverage Shards for library management
Use macros for repeated code patterns
Write tests in parallel with development
Use fiber concurrency for efficient IO
Keep code clean and Ruby-like for readability
Challenges
Build CLI argument parser
Create small REST API
Implement concurrent task runner
Write JSON processor
Develop microservice with fibers