Skip to content
/ kemal Public
forked from kemalcr/kemal

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

Notifications You must be signed in to change notification settings

yalcin/kemal

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

# Kemal [![Build Status](https://travis-ci.org/kemalcr/kemal.svg?branch=master)](https://travis-ci.org/kemalcr/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  

Environment

Accessing the environment (query params, body, content_type, headers, status_code) is super easy. You can use the environment returned from the block:

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

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

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

  # Add headers to your response
  get "/headers" do |env|
    env.add_header "Accept-Language", "tr"
    env.add_header "Authorization", "Token 12345"
  end

Thanks

Thanks to Manas for their awesome work on Frank.

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Crystal 98.8%
  • Ruby 1.2%