This is a default shard.yml and it contains the minimal necessary information about our project. Those are
name specifies the name of the project
version specifies the version of the project. Crystal itself uses semver for version management so it’s a good convention for you to follow.
authors section specifies the authors of the project. By default this is taken from your global git configuration.
license specifies the type of your project license. By default this is MIT.
Okay. That’s great but what can we do with this shard.yml? Well we can use this file to add external libraries(we call it dependency) and manage them without even worrying about any folders / paths e.g.. Sweet isn’t it?
Now that we know the true power of shards let’s add Kemal to our shard.yml and build a simple web application :)
Open up shard.yml. First we need to add Kemal as a dependency to our project. We do this by including
That’s great! Now we added Kemal to our project. First, we need to install it.
$ shards install
Installing kemal (0.14.1)
Installing radix (0.3.0)
Installing kilt (0.3.3)
Okay now we are ready to use Kemal in our project. Open up src/sample.cr
Look how we used require to access Kemal in our program.
$ crystal src/sample.cr
[development] Kemal is ready to lead at http://0.0.0.0:3000
Go to localhost:3000 and see it in action!
Now you know how to add dependencies and use others’ shards :)