Popularity
3.4
Growing
Activity
0.0
Stable
10
2
2
Programming language: Crystal
License: MIT License
Tags:
Web Frameworks
chocolate alternatives and similar shards
Based on the "Web Frameworks" category.
Alternatively, view chocolate alternatives based on common mentions on social networks and blogs.
-
amethyst
Amethyst is a Rails inspired web-framework for Crystal language -
lucky
A full-featured Crystal web framework that catches bugs for you, runs incredibly fast, and helps you write code that lasts. -
amber
A Crystal web framework that makes building applications fast, simple, and enjoyable. Get started with quick prototyping, less bugs, and blazing fast performance. -
kemalyst
A Rails like framework inspired by Kemal but includes the kitchen sink -
spider-gazelle
A Rails esque web framework with a focus on speed and extensibility for crystal lang -
moonshine
Web framework for Crystal language [DEPRECATED in favour of kemal] -
lattice-core
A WebSocket-first object-oriented framework for Crystal -
runcobo
An api framework with type-safe params, elegant json serializer. Thanks for enjoying it! 👻👻 https://runcobo.github.io/docs/ -
Shivneri
Component based MVC web framework based on fort architecture targeting good code structures, modularity & performance. -
luckyframework
Fast, maintainable and confidence boosting web framework
Access the most powerful time series database as a service
Ingest, store, & analyze all types of time series data in a fully-managed, purpose-built database. Keep data forever with low-cost storage and superior data compression.
Promo
www.influxdata.com
Do you think we are missing an alternative of chocolate or a related project?
Popular Comparisons
README
chocolate
Simple web framework and template engine
Installation
Add this to your application's shard.yml
:
dependencies:
chocolate:
github: Grabli66/chocolate
Usage
Need latest crystal compiler to compile some samples.
Hello world
require "chocolate"
include Zephyr
include Chocolate
get "/" do
"Hello, world!"
end
listen {
port 8080
}
Hello with template
require "chocolate"
include Zephyr
include Chocolate
get "/" do
html {
head {
title(text: "Hello world")
}
body {
div(text: "Hello, world!")
}
}
end
listen {
port 8080
}
Hello with view
require "chocolate"
include Zephyr
include Chocolate
class HelloView
def render
html {
head {
title(text: "Hello world")
}
body {
div(text: "Hello, world!")
}
}
end
end
get "/" do
HelloView.new
end
listen {
port 8080
}
Handle params
require "chocolate"
include Zephyr
include Chocolate
get "/registration/success" do
html {
body {
div(css: "result", text: "Success")
}
}
end
get "/blog/:id" do |req|
blog = Database.get_blog(req.params["id"])
blog.to_s
end
post "/registration/singup" do |req|
Database.save_user(req.params["email"], req.params["password"])
redirect("/registration/success")
end
Handle static files
require "chocolate"
include chocolate
include zephyr
listen {
port 8080
static_dir "./static"
}
Handle errors
require "chocolate"
include Zephyr
include Chocolate
on_exception ResourceNotFoundException do
"NOT FOUND"
end
on_exception Exception do
"INTERNAL ERROR"
end
listen {
port 8080
}
JSON response
require "json"
require "chocolate"
include Zephyr
include Chocolate
class Database
def self.get_user(id)
User.new(1, "John", "Doe")
end
end
class User
JSON.mapping({
id: Int32,
name: String,
email: String
})
def initialize(@id, @name, @email)
end
end
get "/user/:id" do |req|
user = Database.get_user(req.params["id"] as String)
json(user)
end
listen {
port 8080
}
View inheritance
require "chocolate"
include Zephyr
include Chocolate
abstract class RootView < View
abstract def render_content
def render
html {
head {
title(text: @title)
}
body {
header {
ul(css: "menu") {
li(text: "Home") {
css_add("active") if @location == :home
}
li(text: "Blog") {
css_add("active") if @location == :blog
}
}
}
include_element(render_content)
}
}
end
end
class HomeView < RootView
def initialize
@title = "Home"
@location = :home
end
def render_content
div(css: "home") {
h1(text: "HOME")
}
end
end
class BlogView < RootView
def initialize
@title = "Blog"
@location = :blog
end
def render_content
div(css: "blog") {
h1(text: "Blog")
}
end
end
get "/" do
HomeView.new
end
get "/blog" do
BlogView.new
end
listen {
port 8080
}
Route group
require "../chocolate/src/**"
include Chocolate
include Zephyr
class SessionNotFoundException < Exception
end
on_exception SessionNotFoundException do
"SESSION NOT FOUND"
end
group do
before do |req|
raise SessionNotFoundException.new unless req.params["session_id"]?
end
get "/user/:id" do |req|
req.params["id"] as String
end
get "/blog/:id" do |req|
req.params["id"] as String
end
end
listen {
port 8080
}
Contributing
- Fork it ( https://github.com/Grabli66/chocolate/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- Grabli66 (https://github.com/Grabli66) Grabli66 - creator, maintainer