/mruby-hibari

A Web application framework for Web servers that support mruby and Rack-based API

Primary LanguageRuby

mruby-hibari

A Web application framework for Web servers that support mruby and Rack-based API.

mruby-hibari currently supports the Web servers below:

Synopsis

Write once, run the same on any servers above.

OOP Style

class MyApp < Hibari::App
  def build
    res.code = 200
    res.headers["content-type"] = "text/html; charset=utf8"
    res.body.push("Hello, World!")
    req.params.each do |k,v|
      res.body.push("#{k}: #{v}")
    end
  end
end

MyApp.new.run

DSL Style

hibari do
  res.code = 200
  res.headers["content-type"] = "text/html; charset=utf8"
  res.body.push("Hello, World!")
  req.params.each do |k,v|
    res.body.push("#{k}: #{v}")
  end
end

How to Setup

ngx_mruby, mod_mruby

  1. Add dependency on mruby-hibari into the build_config.rb in your mruby installation.
  2. Write mruby handler like above.

h2o

  1. git clone at h2o/deps to embed mruby-hibari: cd h2o/deps && git clone https://github.com/kentaro/mruby-hibari
  2. Write mruby handler like above.

API

Hibari::Request

env() => Hash

Read-only accessor to ENV passed from Web server.

uri() => URI

Builds URI and returns it as URI object (See https://github.com/zzak/mruby-uri for details).

params() => Hash

Parses query string and returns it as Hash object.

(This method currently does nothing about decoding or other; it just splits the query string with & and =)

request_method() => String

script_name() => String

path_info() => String

request_uri() => String

query_string() => String

server_name() => String

server_addr() => String

remote_addr() => String

remote_port() => String

scheme() => String

engine_name() => String

Shortcuts to env[XXX].

Hibari::Response

code() => Int

code=(Int) => ()

Accessor to HTTP response code.

headers() => Hash

headers=(Hash) => ()

Accessor to HTTP response headers.

body() => Array

body=(Array) => ()

Accessor to HTTP response body.

to_rack() => Array

Returns an array that follows Rack's spec.

Author

Kentaro Kuribayashi

License

MIT