Skip to content

Instantly share code, notes, and snippets.

@wjlroe
Created February 16, 2012 13:32
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wjlroe/1844853 to your computer and use it in GitHub Desktop.
Save wjlroe/1844853 to your computer and use it in GitHub Desktop.
Basic Rack/Unicorn compatible Webmachine skeleton

A very basic webmachine_ruby example app to show how its done

This is specifically for running webmachine with Unicorn/Rack.

To start off:

bundle
unicorn

You should see "hi" on localhost:8080

require 'webmachine/adapter'
require 'webmachine/adapters/rack'
require File.join(File.dirname(__FILE__), 'my_rest_app')
run App.adapter
module MyRESTApp
module Resources
class Echo < Webmachine::Resource
def to_html
if @request.query.has_key?("ping")
return "<p>PONG</p>"
else
return "<p>Hi. <a href=\"/?ping=me\">ping me</a></p>"
end
end
end
end
end
source 'http://rubygems.org'
gem 'webmachine'
gem 'unicorn'
GEM
remote: http://rubygems.org/
specs:
i18n (0.6.0)
kgio (2.6.0)
rack (1.4.1)
raindrops (0.8.0)
unicorn (4.2.0)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
webmachine (0.4.2)
i18n (>= 0.4.0)
PLATFORMS
ruby
DEPENDENCIES
unicorn
webmachine
require 'webmachine'
require File.join(File.dirname(__FILE__), 'echo_resource')
App = Webmachine::Application.new do |app|
app.configure do |config|
config.adapter = :Rack
end
app.routes do
add ['*'], MyRESTApp::Resources::Echo
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment