Skip to content

ujun/mruby-webapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mruby-webapi

A Web API framework for mruby. Create web app APIs respond to various formats.

install by mrbgems

  • add conf.gem line to build_config.rb
MRuby::Build.new do |conf|

    # ... (snip) ...

    conf.gem :github => 'ujun/mruby-webapi'
end

example

/etc/apache2/mods-available/mruby.conf

<IfModule mod_mruby.c>
  <Location />
    mrubyHandlerMiddle /etc/apache2/webapi.rb
  </Location>
</IfModule>

/etc/apache2/webapi.rb

class MyAPI < Rack::WebAPI

  get "/hoge/{id}" do |id|
    [
      200,
      {'content-type' => 'text/plain; charset=utf-8'},
      ["your id is #{id}"]
    ];
  end

  post "/hoge/{id}/{message}" do |id, message|
    [
      200,
      {'content-type' => 'text/plain; charset=utf-8'},
      ["post message '#{message}' for #{id}"]
    ];
  end

  get "/fuga" do
    [
      200,
      {'content-type' => 'text/plain; charset=utf-8'},
      ["Fuga World!"]
    ];
  end

end

MyAPI.new.run

access example

curl http://localhost/fuga
#=> "Fuga World!"
curl http://localhost/hoge/22
#=> your id is 22

License

under the MIT License:

  • see LICENSE file

About

A Web API framework for mruby.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages