{"id":24755262,"url":"https://github.com/katzer/mruby-yeah","last_synced_at":"2025-10-11T01:31:31.514Z","repository":{"id":46033955,"uuid":"92717796","full_name":"katzer/mruby-yeah","owner":"katzer","description":"mruby on tiny rails","archived":false,"fork":false,"pushed_at":"2023-03-08T13:27:04.000Z","size":90,"stargazers_count":35,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2023-03-11T06:12:49.899Z","etag":null,"topics":["mruby-gem","mruby-shelf","web-application"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/katzer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-29T07:45:22.000Z","updated_at":"2023-03-11T06:12:49.899Z","dependencies_parsed_at":"2022-07-18T21:38:52.639Z","dependency_job_id":null,"html_url":"https://github.com/katzer/mruby-yeah","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katzer%2Fmruby-yeah","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katzer%2Fmruby-yeah/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katzer%2Fmruby-yeah/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katzer%2Fmruby-yeah/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/katzer","download_url":"https://codeload.github.com/katzer/mruby-yeah/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236018676,"owners_count":19082129,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mruby-gem","mruby-shelf","web-application"],"created_at":"2025-01-28T12:37:59.297Z","updated_at":"2025-10-11T01:31:31.184Z","avatar_url":"https://github.com/katzer.png","language":"Ruby","readme":"\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"logo.png\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://travis-ci.com/katzer/mruby-yeah\"\u003e\n        \u003cimg src=\"https://travis-ci.com/katzer/mruby-yeah.svg?branch=master\" alt=\"Build Status\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://codebeat.co/projects/github-com-katzer-mruby-yeah-master\"\u003e\n        \u003cimg src=\"https://codebeat.co/badges/828229e5-c07a-4fc6-ba2a-7afc824685c5\" alt=\"codebeat badge\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://ci.appveyor.com/project/katzer/mruby-yeah/branch/master\"\u003e\n        \u003cimg src=\"https://ci.appveyor.com/api/projects/status/yud3nsyo5tqnvgxx/branch/master?svg=true\" alt=\"Build Status\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n__Yeah!__ is a DSL for quickly creating [shelf applications][shelf] in [mruby][mruby] with minimal effort:\n\n```ruby\n# mrblib/your-mrbgem.rb\n\nextend Yeah::DSL                                      |   extend Yeah::DSL\n                                                      |\nset port: 3000                                        |   opt(:port) { |port| set port: port }\n                                                      |\nget '/hi/{name}' do |name|                            |   get '/hi' do\n  \"Hi #{name}\"                                        |     \"Hi #{params['name'].join(' and ')}\"\nend                                                   |   end\n```\n\n```sh\n$ your-mrbgem \u0026                                       |   $ your-mrbgem --port 8080 \u0026 \nStarting application at http://localhost:3000         |   Starting application at http://localhost:8080\n                                                      |\n$ curl 'localhost:3000/hi/Ben'                        |   $ curl 'localhost:8080/hi?name=Tom\u0026name=Jerry'\nHi Ben                                                |   Hi Tom and Jerry\n```\n\n## Installation\n\nAdd the line below to your `build_config.rb`:\n\n```ruby\nMRuby::Build.new do |conf|\n  # ... (snip) ...\n  conf.gem 'mruby-yeah'\nend\n```\n\nOr add this line to your aplication's `mrbgem.rake`:\n\n```ruby\nMRuby::Gem::Specification.new('your-mrbgem') do |spec|\n  # ... (snap) ...\n  spec.add_dependency 'mruby-yeah'\nend\n```\n\n## Routes\n\nIn Yeah!, a route is an HTTP method paired with a URL-matching pattern. Each route is associated with a block:\n\n```ruby\npost '/' do\n  .. create something ..\nend\n```\n\nRoutes are matched in the order they are defined. The first route that matches the request is invoked.\n\nRoutes with trailing slashes are __not__ different from the ones without:\n\n```ruby\nget '/foo' do\n  # Does match \"GET /foo/\"\nend\n```\n\nUse `root` to specify the default entry point:\n\n```ruby\n# Redirect \"GET /\" to \"GET /public/index.html\"\nroot '/public/index.html'\n```\n\nRoute patterns may include named parameters, accessible via the `params` hash:\n\n```ruby\n# matches \"GET /hello/foo\" and \"GET /hello/bar\"\nget '/hello/{name}' do\n  # params[:name] is 'foo' or 'bar'\n  \"Hello #{params[:name]}!\"\nend\n```\n\nYou can also access named parameters via block parameters:\n\n```ruby\n# matches \"GET /hello/foo\" and \"GET /hello/bar\"\nget '/hello/{name}' do |name|\n  # params[:name] is 'foo' or 'bar'\n  # name stores params[:name]\n  \"Hello #{name}!\"\nend\n```\n\nRoutes may also utilize query parameters:\n\n```ruby\n# matches \"GET /posts?title=foo\u0026author=bar\"\nget '/posts' do\n  title  = params['title']\n  author = params['author']\nend\n```\n\nRoute matching with Regular Expressions:\n\n```ruby\nget '/blog/post/{id:\\\\d+}' do |id|\n  post = Post.find(id)\nend\n```\n\nSupport for regular expression requires __mruby-regexp-pcre__ to be installed before mruby-yeah!\n\nRoutes can also be defined to match any HTTP method:\n\n```ruby\n# matches \"GET /\" and \"PUT /\" and ...\nroute '/', R3::ANY do\n  request[Shelf::REQUEST_METHOD]\nend\n```\n\nLast but not least its possible to get a list of all added HTTP routes:\n\n```ruby\nroutes # =\u003e ['GET /blog/post/{id}']\n```\n\n## Response\n\nEach routing block is invoked within the scope of an instance of `Yeah::Controller`. The class provides access to methods like `request`, `params`, `logger` and `render`.\n\n- `request` returns the Shelf request and is basically a hash.\n\n```ruby\nget '/' do\n  request # =\u003e { 'REQUEST_METHOD' =\u003e 'GET', 'REQUEST_PATH' =\u003e '/', 'User-Agent' =\u003e '...' }\nend\n```\n\n- `params` returns the query params and named URL params. Query params are accessible by string keys and named params by symbol.\n\n```ruby\n# \"GET /blogs/b1/posts/p1?blog_id=b2\"\nget '/blogs/{blog_id}/posts/{post_id}' do\n  params # =\u003e { blog_id: 'b1', post_id: 'p1' }\nend\n```\n\n- `logger` returns the query params and named URL params. Query params are accessible by string keys and named params by symbol. Dont forget to include the required middleware!\n\n```ruby\nuse Shelf::Logger\n\nget '/' do\n  logger # =\u003e \u003cLogger:0x007fae54987308\u003e\nend\n```\n\n- `render` returns a well-formed shelf response. The method allows varoius kind of invokation:\n\n```ruby\nget '/500' do                     |   get '/yeah' do\n  render 500                      |     render html: '\u003ch1\u003eYeah!\u003c/h1\u003e'\nend                               |   end\n                                  |\nget '/say_hi' do                  |   post '/api/stats' do\n  render 'Hi'                     |     render json: Stats.create(params), status: 201, headers: {...}\nend                               |   end\n                                  |\nget '/say_hello' do               |   get '/' do\n  'Hello'                         |     render redirect: 'public/index.html'\nend                               |   end\n```\n\n## Controller\n\nInstead of a code block to execute a route also accepts an controller and an action similar to Rails.\n\n```ruby\nclass GreetingsController \u003c Yeah::Controller\n  def greet(name)\n    render \"Hello #{name.capitalize}\"\n  end\nend\n\nYeah.application.routes.draw do\n  get 'greet/{name}', to: 'greetings#greet'\nend\n\nYeah.application.configure :production do\n  log_folder '/logs', 'iss.log', 'iss.err'\nend\n\nYeah.application.run! port: 3000\n```\n\n## Command Line Arguments\n\nYeah! ships with a small opt parser. Each option is associated with a block:\n\n```ruby\n# matches \"your-mrbgem --port 80\" or \"your-mrbgem -p 80\"\nopt :port, :int, 8080 do |port|\n  # port is 80\n  set :port, port\nend\n```\n\nOpts can have a default value. The block will be invoked in any case either with the command-line value, its default value or just _nil_.\n\nSometimes however it is intended to only print out some meta informations for a single given option and then exit without starting the server:\n\n```ruby\n# matches \"your-mrbgem --version\" or \"your-mrbgem -v\"\nopt! :version do\n  # prints 'v1.0.0' on STDOUT and exit\n  'v1.0.0'\nend\n```\n\n## Configuration\n\nRun once, at startup, in any environment:\n\n```ruby\nconfigure do\n  # setting one option\n  set :option, 'value'\n  # setting multiple options\n  set a: 1, b: 2\n  # same as `set :option, true`\n  enable :option\n  # same as `set :option, false`\n  disable :option\nend\n```\n\nRun only when the environment (`SHELF_ENV` environment variable) is set to `production`:\n\n```ruby\nconfigure :production do\n  ...\nend\n```\n\nRun only when the environment is set to either `development` or `test`:\n\n```ruby\nconfigure :development, :test do\n  ...\nend\n```\n\nYou can access those options via `settings`:\n\n```ruby\nconfigure do\n  set :foo, 'bar'\nend\n\nget '/' do\n  settings[:foo] # =\u003e 'bar'\nend\n```\n\n## Shelf Middleware\n\nYeah! rides on [Shelf][shelf], a minimal standard interface for mruby web frameworks. One of Shelf's most interesting capabilities for application developers is support for \"middleware\" -- components that sit between the server and your application monitoring and/or manipulating the HTTP request/response to provide various types of common functionality.\n\nSinatra makes building Rack middleware pipelines a cinch via a top-level `use` method:\n\n```ruby\nuse Shelf::CatchError\nuse MyCustomMiddleware\n\nget '/hello' do\n  'Hello World'\nend\n```\n\nThe semantics of `use` are identical to those defined for the [Shelf::Builder][builder] DSL. For example, the use method accepts multiple/variable args as well as blocks:\n\n```ruby\nuse Shelf::Static, urls: ['/public'], root: ENV['DOCUMENT_ROOT']\n```\n\nShelf is distributed with a variety of standard middleware for logging, debugging, and URL routing. Yeah! uses many of these components automatically based on configuration so you typically don't have to use them explicitly.\n\n## Server\n\nYeah! works with any Shelf-compatible web server. Right now these are _mruby-simplehttpserver_ and _mruby-heeler_:\n\n```ruby\nset :server, 'simplehttpserver' # =\u003e Default\n```\n\nHowever its possible to register handlers for other servers. See [here][server] for more info.\n\n## Development\n\nClone the repo:\n    \n    $ git clone https://github.com/katzer/mruby-yeah.git \u0026\u0026 cd mruby-yeah/\n\nCompile the source:\n\n    $ rake compile\n\nRun the tests:\n\n    $ rake test\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/katzer/mruby-yeah.\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\n## Authors\n\n- Sebastián Katzer, Fa. appPlant GmbH\n\n## License\n\nThe mgem is available as open source under the terms of the [MIT License][license].\n\nMade with :yum: in Leipzig\n\n© 2017 [appPlant GmbH][appplant]\n\n[shelf]: https://github.com/katzer/mruby-shelf\n[mruby]: https://github.com/mruby/mruby\n[builder]: https://github.com/katzer/mruby-shelf/blob/master/mrblib/shelf/builder.rb\n[server]: https://github.com/katzer/mruby-shelf#handler\n[license]: http://opensource.org/licenses/MIT\n[appplant]: www.appplant.de\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatzer%2Fmruby-yeah","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkatzer%2Fmruby-yeah","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatzer%2Fmruby-yeah/lists"}