Project

krack

0.0
No commit activity in last 3 years
No release in over 3 years
Simple JSON APIs on Rack
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 1.4.5
 Project Readme

Krack

Simple JSON APIs on Rack. Like so:

# config.ru
require 'krack'

class Widget # < "ORM"
  DB = {
    "1" => {name: "Foo", color: "Black"},
    "2" => {name: "Bar", color: "White"}
  }
  def self.all; DB end
  def self.find(id); DB[id] end
end

module Widgets
  class Index < Krack::Endpoint
    def respond
      {widgets: Widget.all}
    end
  end

  class Show < Krack::Endpoint
    def respond
      widget = Widget.find(params["id"]) or throw :halt, 404
      {widget: widget}
    end
  end
end

run Krack::Router.new {
  get "/widgets",     Widgets::Index
  get "/widgets/:id", Widgets::Show
}

License

This content is released under the MIT License.