Created
October 2, 2014 13:35
-
-
Save porras/e9b7edfea6b817ac8afe to your computer and use it in GitHub Desktop.
Run your objects as web apps in an insanely decoupled way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Object | |
def to_app | |
lambda do |env| | |
_, method, args = env['REQUEST_PATH'].split('/') | |
[200, {}, [self.send(method, *args).to_s]] | |
end | |
end | |
end | |
class HelloWorld | |
def hello(name) | |
"Hello, #{name}!" | |
end | |
end | |
run HelloWorld.new.to_app | |
# This is not my idea, I read it time ago and wasn't able to find it today so I rewrote it (not sure the implementation is the same) | |
# start running rackup | |
# $ curl http://localhost:9292/hello/Txus | |
# Hello, Txus! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment