{"id":24755246,"url":"https://github.com/katzer/mruby-r3","last_synced_at":"2025-10-08T19:25:42.812Z","repository":{"id":138108997,"uuid":"90658941","full_name":"katzer/mruby-r3","owner":"katzer","description":"mruby bindings for libr3","archived":false,"fork":false,"pushed_at":"2024-08-29T21:34:48.000Z","size":275,"stargazers_count":15,"open_issues_count":2,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-29T23:46:21.248Z","etag":null,"topics":["libr3","mruby-bindings","mruby-gem","path-dispatcher"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-08T18:17:17.000Z","updated_at":"2024-08-29T21:34:51.000Z","dependencies_parsed_at":"2024-08-29T23:22:18.254Z","dependency_job_id":null,"html_url":"https://github.com/katzer/mruby-r3","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katzer%2Fmruby-r3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katzer%2Fmruby-r3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katzer%2Fmruby-r3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katzer%2Fmruby-r3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/katzer","download_url":"https://codeload.github.com/katzer/mruby-r3/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236018631,"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":["libr3","mruby-bindings","mruby-gem","path-dispatcher"],"created_at":"2025-01-28T12:37:55.742Z","updated_at":"2025-10-08T19:25:37.793Z","avatar_url":"https://github.com/katzer.png","language":"C","readme":"# mruby-r3 \u003cbr\u003e [![Build Status](https://travis-ci.com/katzer/mruby-r3.svg?branch=master)](https://travis-ci.com/katzer/mruby-r3) [![Build status](https://ci.appveyor.com/api/projects/status/dhiknegayv8k18mw/branch/master?svg=true)](https://ci.appveyor.com/project/katzer/mruby-r3/branch/master)\n\nmruby binding for [libr3][r3], a high-performance path dispatching library.\n\n```ruby\ntree \u003c\u003c '/users/{user_id}/feeds/{feed_id}'\n\ntree.match '/users/1/feeds/2'\n# =\u003e { user_id: '1', feed_id: '2' }\n```\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 mgem: 'mruby-regexp-pcre' # Optional\n  conf.gem mgem: 'mruby-r3'\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-regexp-pcre' # Optional\n  spec.add_dependency 'mruby-r3'\nend\n```\n\n\n## Usage\n\nFirst of all a tree object has to be created.\n\n```ruby\ntree = R3::Tree.new\n```\n\nThe size grows dynamically. However the initializer accepts an optional initial size.\nThe default initial size is up to 5 routes.\n\n```ruby\ntree = R3::Tree.new(100)\n```\n\nThe pattern syntax for routes is the following. Enhanced support for regular expression requires __mruby-regexp-pcre__ to be installed!\n\n    /blog/post/{id}      use [^/]+ regular expression by default.\n    /blog/post/{id:\\d+}  use `\\d+` regular expression instead of default.\n\nRoutes can be added to the tree at any time, however dont forget to call __compile__ before using them.\n\n```ruby\ntree \u003c\u003c '/'\ntree \u003c\u003c '/blog/post'\ntree \u003c\u003c '/blog/post/{id}'\ntree \u003c\u003c '/user/{user_id}/feeds/{feed_id}'\n```\n\nIts also possible to specify the HTML method rather then to allow any.\n\n```ruby\ntree.add('/blog/post/{id:\\\\d+}', R3::DELETE)\n```\n\nOnce the tree has been compiled he's ready for dispatching.\n\n```ruby\ntree \u003c\u003c '/'\ntree.add '/users', R3::ANY\ntree.add '/posts', R3::GET\ntree.add '/users/{user_id}/feeds/{feed_id}', R3::GET\ntree.compile\n\ntree.routes\n# =\u003e ['GET /users/{user_id}/feeds/{feed_id}', ...]\n\ntree.match? '/'\n# =\u003e true\ntree.match '/'\n# =\u003e {}\n\ntree.match? '/other'\n# =\u003e false\ntree.match '/other'\n# =\u003e nil\n\ntree.match? '/users', R3::POST\n# =\u003e true\ntree.match? '/posts', R3::POST\n# =\u003e false\n\ntree.match '/users/1/feeds/2'\n# =\u003e { user_id: '1', feed_id: '2' }\ntree.match '/users/1/feeds/2', R3::POST\n# =\u003e nil\n```\n\nBefore you're writing your own URL map, you can make use of the built-in feature to add any kind of data with the route.\n\n```ruby\ntree.add('/user/{name}', R3::ANY, -\u003e { 'callback handler' })\ntree.compile\n\nparams, handler = tree.match('/user/bernd')\nhandler.call\n# =\u003e 'callback handler'\n```\n\n\n## Development\n\nClone the repo:\n    \n    $ git clone https://github.com/katzer/mruby-r3.git \u0026\u0026 cd mruby-r3/\n\nCompile the source:\n\n    $ rake compile\n\nRun the tests:\n\n    $ rake test\n\n\n## TODO\n\n1. Add a route for multiple HTTP methods.\n2. missing asprintf() for MingGW 32-bit compiler. \n\n\n## Authors\n\n- Sebastián Katzer, Fa. appPlant GmbH\n\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[r3]: https://github.com/c9s/r3\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-r3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkatzer%2Fmruby-r3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatzer%2Fmruby-r3/lists"}