为Web服务器提供mruby和Rack-based API支持的Web框架:mruby-hibari

jopen 9年前

针对Web服务器的Web应用程序框架,提供mruby和基于Rack的API支持。

mruby-hibari 当前支持以下服务器:

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 cloneat 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 toENVpassed from Web server.

uri()=>URI

Builds URI and returns it asURIobject.

params()=>Hash

Parses query string and returns it asHashobject.

(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 toenv[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.

项目主页:http://www.open-open.com/lib/view/home/1442470425399