The strange case of Dr. Rack and Mr. Hyde

Hyde is a library that provides a DSL for creating web applications. As of now it is using Rack as the webserver adapter, but ideally it shouldn't take much work to make it run on top of any webserver.

Hyde was made mostly for fun. Ideally it will become something more, but as of yet it's just an experiment revolving around Ruby Metaprogramming and its DSL capabilities.

Examples

A simple "Hello, World!" app using Hyde

require 'hyde'

app = Hyde::Server.new do
  get "/hello" do
    header "content-type", "text/plain"
    "Hello world!"
  end
end

run app

A push/pull stack as an app

require 'hyde'

stack = []

app = Hyde::Server.new do
  get "/pop" do
    header 'content-type', 'text/plain'
    stack.pop.to_s
  end
  post "/push" do
    header 'content-type', 'text/plain'
    stack.push(request.body)
    request.body
  end
end

run app

Several push/pull buckets

require 'hyde'

stack = { "1" => [], "2" => [], "3" => [] }

app = Hyde::Server.new do
  path "bucket_(1|2|3)" do
    get "pop" do |bucket|
      header "content-type", "text/plain"
      stack[bucket].pop.to_s
    end
    post "push" do |bucket|
      header "content-type", "text/plain"
      stack[bucket].push(request.body)
      request.body
    end
  end
end

run app

Static file serving (Note: index applies only to /var/www (to the path its defined in))

require 'hyde'

app = Hyde::Server.new do
  root "/var/www"
  index ["index.html","index.htm"]
  serve "**/*.(html|htm)"
end

run app

Logging on a particular path

require 'hyde'

app = Hyde::Server.new do
  path "unimportant" do
    get "version" do
      header "content-type", "text/plain"
      "1337 (the best one)"
    end
  end
  path "important" do
    preprocess do |req|
      # Implement logging logic here
      puts "Client at #{req.headers['remote-addr']} wanted to access something /important!"
    end
    get "answer" do
      header "content-type", "application/json"
      '{"answer":42, "desc":"something important!"}'
    end
  end
end

run app

And a lot more to be found in /examples in this repo.

Documentation

Someday it's gonna be there somewhere

License

    Hyde - an HTTP request pattern matching system 
    Copyright (C) 2022 yessiest (yessiest@memeware.net)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.