{"action":"created","issue":{"url":"https://api.github.com/repos/lotus/router/issues/41","labels_url":"https://api.github.com/repos/lotus/router/issues/41/labels{/name}","comments_url":"https://api.github.com/repos/lotus/router/issues/41/comments","events_url":"https://api.github.com/repos/lotus/router/issues/41/events","html_url":"https://github.com/lotus/router/issues/41","id":57225055,"number":41,"title":"Allow configuration of default routes for `resource`/`resources`","user":{"login":"Emily","id":240689,"avatar_url":"https://avatars.githubusercontent.com/u/240689?v=3","gravatar_id":"","url":"https://api.github.com/users/Emily","html_url":"https://github.com/Emily","followers_url":"https://api.github.com/users/Emily/followers","following_url":"https://api.github.com/users/Emily/following{/other_user}","gists_url":"https://api.github.com/users/Emily/gists{/gist_id}","starred_url":"https://api.github.com/users/Emily/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Emily/subscriptions","organizations_url":"https://api.github.com/users/Emily/orgs","repos_url":"https://api.github.com/users/Emily/repos","events_url":"https://api.github.com/users/Emily/events{/privacy}","received_events_url":"https://api.github.com/users/Emily/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-02-10T19:38:05Z","updated_at":"2015-02-11T09:12:27Z","closed_at":null,"body":"While I think the current set of routes generated by `resources` is a reasonable default, the inability to customize, or reuse chunks of routes is somewhat cumbersome when an app deviates from that particular set of routes. \r\n\r\nFor instance, http://jsonapi.org/ requires supporting PUT for updates, and allows APIs to optionally support PATCH (with a very specific format). When building an API that conforms to that specification (and the same goes for many other specs), it is a pain to have to be specifying things like:\r\n\r\n```ruby\r\nresources 'widgets' do\r\n  member do\r\n    put '', to: 'widgets#update'\r\n  end\r\nend\r\n```\r\n\r\nIt is also very visually noisy. It'd be nice if either the set of routes that `resources` creates were configurable, or if it were possible to simply configure extra methods that behaved similarly to `resources` that define a different set of routes, e.g.\r\n\r\n```ruby\r\njson_api_resources 'widgets'\r\n```\r\n\r\nOr perhaps something that behaves a bit like Rails's routing concerns, e.g.\r\n\r\n```ruby\r\nresources :widgets do\r\n  concerns :json_api_resource # adds in the handful of extra routes\r\nend\r\n```\r\n\r\nMy favorite is probably allowing `resources` to be configured, or the `resources` like method approach. I'd be happy to put together a PR for one of them, especially if it can be slipped in before support for < ruby 2.2 is dropped (as I'm likely stuck using 2.1 for several months). "},"comment":{"url":"https://api.github.com/repos/lotus/router/issues/comments/73851703","html_url":"https://github.com/lotus/router/issues/41#issuecomment-73851703","issue_url":"https://api.github.com/repos/lotus/router/issues/41","id":73851703,"user":{"login":"jodosha","id":5089,"avatar_url":"https://avatars.githubusercontent.com/u/5089?v=3","gravatar_id":"","url":"https://api.github.com/users/jodosha","html_url":"https://github.com/jodosha","followers_url":"https://api.github.com/users/jodosha/followers","following_url":"https://api.github.com/users/jodosha/following{/other_user}","gists_url":"https://api.github.com/users/jodosha/gists{/gist_id}","starred_url":"https://api.github.com/users/jodosha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jodosha/subscriptions","organizations_url":"https://api.github.com/users/jodosha/orgs","repos_url":"https://api.github.com/users/jodosha/repos","events_url":"https://api.github.com/users/jodosha/events{/privacy}","received_events_url":"https://api.github.com/users/jodosha/received_events","type":"User","site_admin":false},"created_at":"2015-02-11T09:12:27Z","updated_at":"2015-02-11T09:12:27Z","body":"@Emily Thanks for the great reply.\r\n\r\n### Class vs instance configuration\r\n\r\nLotus::Router is the one of the few Lotus framework that don't need class level configurations. I would keep it as it is, so those configurations should be moved at the instance level.\r\n\r\nThe reason is simple. When class level configurations are involved, multiple instances of a framework can't live together in the same Ruby process without the _\"framework duplication\"_ technique. This is something that we apply to Controller, View and Model.\r\n\r\nIf we change how Lotus::Router works, we should change a lot of other foundations that Lotus is relying on. I'm very conservative on this aspect.\r\n\r\n### Some ideas\r\n\r\nWhat if we do:\r\n\r\n```ruby\r\nrouter = Lotus::Router.new do\r\n  configure do\r\n    resources do\r\n       # ...\r\n    end\r\n\r\n    resource do\r\n       # ...\r\n    end\r\n  end\r\nend\r\n```\r\n\r\nThose two blocks can express RESTful resources as you have expressed.\r\nThe `:name` option can be called `:verb` :)\r\n\r\nThe internals of the framework aren't that much flexibile to support this feature without changing them a lot. I understand that you want to get your job done. So let me suggest a few of quick ideas to get you up and running again.\r\n\r\n  * Would be enough to support both `PUT` and `PATCH` for update operations to get compliant to jsonapi.org ?\r\n  * Have you considered to subclass `Lotus::Router` and to override `#resources` to get your wanted behavior?\r\n\r\n### One configuration per router instance\r\n\r\n> I'm not sure it's necessary, but it might be nice for applications which have both endpoints intended for direct human consumption (html, etc...) and APIs intended for machine consumption.\r\n\r\n:-1: \r\n\r\nThe way that Lotus wants to guide developers is to have multiple applications in the same Ruby process, one for each area. If you use Lotus full stack (`lotusrb` gem), you can have `apps/web`, `apps/api` etc..\r\n\r\nThis architecture helps to keep things simple, decoupled, faster and easy to extract.\r\n\r\n### Ruby version\r\n\r\nI'm glad it doesn't depend on Lotus. But technically, which gems or other kind of problems prevent you to do the upgrade? Can you please share them on this thread? https://discuss.lotusrb.org/t/supported-ruby-vms/28/10\r\n\r\nThank you very much!"}}