shard-kemal/docs/tutorial.md

89 lines
1.4 KiB
Markdown
Raw Normal View History

2015-12-04 11:26:15 +00:00
# Kemal Tutorial
2015-12-05 11:52:07 +00:00
## 1. Install Crystal
2015-12-04 11:26:15 +00:00
```
brew update
brew install crystal-lang
```
2015-12-05 11:52:07 +00:00
## 2. Installing Kemal
2015-12-04 11:26:15 +00:00
You should create your application first:
```
crystal init app awesome_web_project
cd awesome_web_project
```
Then add *kemal* to the `shard.yml` file as a dependency.
2015-12-04 11:36:06 +00:00
```yml
2015-12-04 11:26:15 +00:00
dependencies:
kemal:
github: sdogruyol/kemal
branch: master
```
You should run `shards` to get dependencies:
```
shards install
```
2015-12-05 11:52:07 +00:00
It will output something like that:
```
$ shards install
Updating https://github.com/sdogruyol/kemal.git
Installing kemal (master)
```
## 3. Include Kemal into your project
2015-12-04 11:26:15 +00:00
Open `awesome_web_project/src/awesome_web_project.cr` and require `kemal` to use Kemal.
2015-12-04 11:36:06 +00:00
```ruby
2015-12-04 11:26:15 +00:00
require 'kemal'
```
2015-12-05 11:52:07 +00:00
## 4. Hack your project
2015-12-04 11:26:15 +00:00
Do some awesome stuff with awesome Kemal.
2015-12-04 11:36:06 +00:00
```ruby
2015-12-04 11:26:15 +00:00
get "/" do
"Hello World!"
end
```
2015-12-05 11:52:07 +00:00
All the code should look like this:
```ruby
require "./crystal_test/*"
require "kemal"
module AwesomeWebProject
get "/" do
"Hello World!"
end
end
```
## 5. Run your awesome web project.
2015-12-04 11:26:15 +00:00
```
crystal build --release src/awesome_web_project.cr
./awesome_web_project
```
2015-12-05 11:52:07 +00:00
You should see some logs like these:
```
[development] Kemal is ready to lead at http://0.0.0.0:3000
2015-12-01 13:47:48 +0200 | 200 | GET / - (666µs)
2015-12-05 13:47:48 +0200 | 404 | GET /favicon.ico - (14µs)
```
2015-12-04 11:26:15 +00:00
Now you can be happy with your new, very fast, readable web project.