Go to file
Sdogruyol 5bc81e7e5b Change single quotes to double quotes 2015-10-29 11:42:54 +02:00
samples Removed redundant code from hello_world 2015-10-24 22:57:40 +03:00
spec Changed default content-type to text/html 2015-10-28 21:55:17 +02:00
src Fixed samples url 2015-10-29 11:22:44 +02:00
.gitignore Initial commit 2014-06-11 20:41:02 -03:00
Guardfile Added Guardfile 2015-10-28 17:37:51 +02:00
README.md Change single quotes to double quotes 2015-10-29 11:42:54 +02:00
shard.yml Added shard.yml 2015-10-23 21:01:30 +03:00

README.md

# Kemal

Lightning Fast, Super Simple web framework for Crystal. Inspired by Sinatra

Kemal is under heavy development and currently supports Crystal 0.9.0.

Super Simple <3

require "kemal"

get "/" do
  "Hello World!"
end

Build and run!

crystal build --release src/kemal_sample.cr
./kemal_sample

Go to http://localhost:3000

Check samples for more.

Installation

Add it to your shard.yml

dependencies:
  kemal:
    github: kemalcr/kemal
    branch: master

Routes

In Kemal, a route is an HTTP method paired with a URL-matching pattern. Each route is associated with a block:

  get "/" do
  .. show something ..
  end

  post "/" do
  .. create something ..
  end

  put "/" do
  .. replace something ..
  end

  patch "/" do
  .. modify something ..
  end

  delete "/" do
  .. annihilate something ..
  end  

Context

Accessing the request context (query params, body, headers e.g) is super easy. You can use the context returned from the block:

  # Matches /hello/kemal
  get "/hello/:name" do |ctx|
    name = ctx.params["name"]
    "Hello back to #{name}"
  end

  # Matches /resize?width=200&height=200
  get "/resize" do |ctx|
    width = ctx.params["width"]
    height = ctx.params["height"]
  end

Content Type

Kemal uses text/html as the default content type. You can change it via the context.

  # Set the content as application/json and return JSON
  get "/user.json" do |ctx|
    kemal = {name: "Kemal", language: "Crystal"}
    ctx.set_content_type "application/json"
    kemal.to_json
  end

Thanks

Thanks to Manas for their awesome work on Frank.