require 'sinatra' require 'json' module Riedi class Server < Sinatra::Base def initialize(options = {}) @storage = Storage.new(options) super end get '/' do 'Riedi (try /status)' end get '/status' do @storage.status end get '/keys' do @storage.keys.to_json end post '/store/:key' do @storage.set(params[:key], params[:value]) end get '/store/:key' do value = @storage.get(params[:key]) if value value else error 404 end end delete '/store/:key' do count = @storage.del(params[:key]) if count > 0 count.to_s else error 404 end end end end