{"id":15408431,"url":"https://github.com/yusukebe/plainrouter","last_synced_at":"2025-08-01T03:05:00.111Z","repository":{"id":56888213,"uuid":"56822186","full_name":"yusukebe/plainrouter","owner":"yusukebe","description":"Fast and simple routing engine for Ruby","archived":false,"fork":false,"pushed_at":"2016-04-22T16:51:48.000Z","size":22,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-28T08:43:38.112Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/yusukebe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-22T03:02:22.000Z","updated_at":"2021-12-13T09:20:06.000Z","dependencies_parsed_at":"2022-08-20T16:00:09.365Z","dependency_job_id":null,"html_url":"https://github.com/yusukebe/plainrouter","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/yusukebe/plainrouter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusukebe%2Fplainrouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusukebe%2Fplainrouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusukebe%2Fplainrouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusukebe%2Fplainrouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yusukebe","download_url":"https://codeload.github.com/yusukebe/plainrouter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yusukebe%2Fplainrouter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268162343,"owners_count":24205701,"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","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-01T16:33:58.591Z","updated_at":"2025-08-01T03:05:00.087Z","avatar_url":"https://github.com/yusukebe.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PlainRouter\n\n[![Build Status](https://travis-ci.org/yusukebe/plainrouter.svg?branch=master)](https://travis-ci.org/yusukebe/plainrouter)\n[![Gem Version](https://badge.fury.io/rb/plainrouter.svg)](https://badge.fury.io/rb/plainrouter)\n\nPlainRouter is a **fast** and **simple** routing engine for Ruby. Using `PlainRouter::Method`, you can quickly make web application framework like Sinatra. PlainRouter is a porting project of [Route::Boom](https://metacpan.org/pod/Router::Boom).\n\n## Install\n\nAdd this line to your application's Gemfile:\n\n```\ngem 'plainrouter'\n```\n\nAnd then execute:\n\n```\n$ bundle\n```\n\nOr install it yourself as:\n\n```\n$ gem install plainrouter\n```\n\n## Usage\n\nHere is synopsis of using **PlainRouter**\n\n```ruby\nrouter = PlainRouter.new\nrouter.add('/', 'dispatch_root')\nrouter.add('/entries', 'dispatch_entries')\nrouter.add('/entries/:id', 'dispatch_permalink')\nrouter.add('/users/:user/{year}', 'dispatch_year')\nrouter.add('/users/:user/{year}/{month:\\d+}', 'dispatch_month')\n\ndest, captured = router.match(env['PATH_INFO'])\n```\n\n**PlainRouter::Method** supports HTTP methods. Sinatra-like Web Framework and Application are below\n\n```ruby\nclass SinatraLikeFramework\n  def initialize\n    @router = PlainRouter::Method.new\n    self.routes\n  end\n  def routes\n  end\n  def get(path, \u0026block)\n    @router.add('GET', path, block)\n  end\n  def call(env)\n    block, params = @router.match(env['REQUEST_METHOD'], env['PATH_INFO'])\n    unless block.instance_of?(Proc)\n      return not_found\n    end\n    response = block.call(params)\n    if response.instance_of?(Array)\n      return response\n    elsif response.instance_of?(String)\n      return [200, {\"Content-Type\" =\u003e \"text/plain\"}, [response]]\n    end\n    not_found\n  end\n  def not_found\n    [404, {\"Content-Type\" =\u003e \"text/plain\"}, ['Not Found']]    \n  end\nend\n\nclass SinatraLikeApplication \u003c SinatraLikeFramework\n  def routes\n    get '/' do\n      'Hello World!'\n    end\n    get '/user/:name' do |params|\n      \"Hello #{params['name']}!\"\n    end\n  end\nend\n\nrun SinatraLikeApplication.new\n```\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n## See Also\n\n* [Rooter::Boom](https://metacpan.org/pod/Router::Boom)\n* [rack-router](https://github.com/pjb3/rack-router)\n\n## Author\n\nYusuke Wada \u003chttps://github.com/yusukebe\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyusukebe%2Fplainrouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyusukebe%2Fplainrouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyusukebe%2Fplainrouter/lists"}