|
||
---|---|---|
examples | ||
lib | ||
test | ||
.gitignore | ||
.yardopts | ||
COPYING.txt | ||
HACKING.md | ||
LAYOUT.md | ||
LICENSE.md | ||
README.md | ||
landline.gemspec |
README.md
Landline - an HTTP DSL
Landline is a library that provides a minimalistic DSL for creating web services. It doesn't include patterns, middleware, or anything that could be considered application logic. It does a few things, and hopefully it does them well:
- Routing HTTP requests to handlers
- Processing HTTP requests (cookies, headers, etc.)
- Filtering, preprocessing and postprocessing requests
- Creating responses from templates using various template engines
- Parsing and handling forms and queries
- Connecting multiple Landline applications together
As such, the library is pretty thin and can be used to build more complex 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.
Landline 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 Landline
require 'landline'
app = Landline::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 'landline'
stack = []
app = Landline::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 'landline'
stack = { "1" => [], "2" => [], "3" => [] }
app = Landline::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 'landline'
app = Landline::Server.new do
root "/var/www"
index ["index.html","index.htm"]
serve "**/*.(html|htm)"
end
run app
Logging on a particular path
require 'landline'
app = Landline::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.
Name
The name is, quite literally, a metaphor for request routing.
Documentation
Documentation can be generated using yard doc
.
For things to render correctly, please install the redcarpet
gem.
License
Landline - an HTTP request pattern matching system
Copyright (C) 2022 yessiest (yessiest@text.512mb.org)
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/>.