Nile webframework
A demonstrative and basic ruby webframework implementing http daemon from scratch.
You can register a route and return the body:
#!/usr/bin/env ruby
require 'nile'
n = Nile::Core.new :bind => '0.0.0.0', :port => 7125
n.get '/' do
[200, {'Content-Type' => 'text/html'}, ['<h1>Hello Nile !</h1>']]
end
n.post '/status' do |env|
data = JSON.parse(env[:req][:body])
puts data
puts env[:params]
[200, {'Content-Type' => 'application/json'}, [JSON.pretty_generate({:status => 'ok'})]]
end
n.run
Using the http daemon
Nile includes an http daemon written in pure ruby from scratch, just for didactic purposes. You can use it this way:
#!/usr/bin/env ruby
require 'nile'
class HttpHandler
def handle req, sock
[200, {'Content-Type' => 'text/plain'}, ['Hello from Nile !']]
end
end
http = Nile::HttpServer.new "0.0.0.0", 7125, HttpHandler.new
http.serve