Skip to content

lauri/krack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Simple JSON APIs on Rack

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages