{"id":13507973,"url":"https://github.com/sheharyarn/better_params","last_synced_at":"2025-04-09T18:18:14.540Z","repository":{"id":57479603,"uuid":"94277622","full_name":"sheharyarn/better_params","owner":"sheharyarn","description":"Cleaner request parameters in Elixir web applications 🙌","archived":false,"fork":false,"pushed_at":"2018-10-24T00:46:57.000Z","size":28,"stargazers_count":97,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-09T18:18:09.496Z","etag":null,"topics":["elixir","phoenix-framework","plug","request-handler"],"latest_commit_sha":null,"homepage":"","language":"Elixir","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/sheharyarn.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-06-14T02:04:01.000Z","updated_at":"2024-04-07T22:57:16.000Z","dependencies_parsed_at":"2022-09-17T05:03:05.003Z","dependency_job_id":null,"html_url":"https://github.com/sheharyarn/better_params","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheharyarn%2Fbetter_params","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheharyarn%2Fbetter_params/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheharyarn%2Fbetter_params/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sheharyarn%2Fbetter_params/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sheharyarn","download_url":"https://codeload.github.com/sheharyarn/better_params/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248085326,"owners_count":21045139,"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":["elixir","phoenix-framework","plug","request-handler"],"created_at":"2024-08-01T02:00:44.703Z","updated_at":"2025-04-09T18:18:14.523Z","avatar_url":"https://github.com/sheharyarn.png","language":"Elixir","funding_links":[],"categories":["Framework Components"],"sub_categories":[],"readme":"[BetterParams][docs]\n====================\n\n[![Build Status][shield-travis]][travis-ci]\n[![Coverage Status][shield-inch]][docs]\n[![Version][shield-version]][hexpm]\n[![License][shield-license]][hexpm]\n\n\u003e Cleaner request parameters in Elixir web applications 🙌\n\n`BetterParams` is a simple Elixir [Plug][plug] that allows passed\nrequest parameters to be called as `atoms` instead of Strings. The\nsole purpose of this Plug is to pattern match on maps with atom keys\ninstead of string keys in routers/controllers to calm my OCD down.\n\n\u003cbr\u003e\n\n\n\n\n## Usage\n\nOnce installed, it lets you pattern match request parameters like\n`%{id: id}` instead of `%{\"id\" =\u003e id}` in Phoenix applications:\n\n```elixir\n# web/controllers/some_controller.ex\n\ndef show(conn, %{id: id}) do\n  # do something\nend\n\ndef create(conn, %{id: id, post: %{title: title, body: body}}) do\n  # do something\nend\n```\n\n\n#### Notes\n\n - Implementation uses [`String.to_existing_atom`][string-atom] to prevent\n   against [DoS attacks][gh-issue-ddos], so it only converts those params\n   to atoms that you use in your application.\n - You can continue to use String keys without breaking your existing\n   matches if you want. All request parameters are available for both\n   `String` and `Atom` keys (that have already been defined in the\n   application).\n - This doesn't pollute your Request Logs with duplicate params.\n - For other `Plug.Router` based applications, you can also access request\n   params similarly by calling them like `conn.params[:id]` or\n  `conn.params.post.title`.\n\n\u003cbr\u003e\n\n\n\n\n## Installation\n\nAdd `better_params` to your project dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:better_params, \"~\u003e 0.5.0\"}]\nend\n```\n\n\n\n### Phoenix Framework\n\nFor Phoenix applications, call the plug at the end of the `controller`\nmethod in `web/web.ex` (inside the `quote` block):\n\n```elixir\n# web/web.ex\n\ndef controller do\n  quote do\n    use Phoenix.Controller\n\n    # Other stuff...\n\n    plug BetterParams\n  end\nend\n```\n\nAlternatively, you can also call it your Router Pipelines or in\nindividual controllers directly.\n\n\n\n### Other Plug.Router Apps\n\nFor other applications using `Plug.Router`, call the Plug anytime after\ncalling the `:match` and `:dispatch` plugs:\n\n```elixir\ndefmodule MyApp.Router do\n  use Plug.Router\n\n  plug :match\n  plug :dispatch\n  plug BetterParams\n\n  # Rest of the router...\nend\n\n```\n\n\n\n### Removing String Keys Entirely\n\nIf your use case calls for a params object with _only_ `Atom` keys, you\nmay pass the option `drop_string_keys` to the plug. Much as it says on\nthe can, this will replace the `String`-type keys altogether, rather\nthan preserving them alongside the `Atom` keys.\n\n```elixir\nplug BetterParams, drop_string_keys: true\n```\n\n\u003cbr\u003e\n\n\n\n\n## Roadmap\n\n - [x] Write Tests\n - [x] Write Documentation\n - [x] Symbolize the collective `params` map\n - [x] Option to remove string keys entirely\n - [ ] Symbolize [individual parameter maps][plug-params] (if the need arises)\n    - [ ] `path_params`\n    - [ ] `body_params`\n    - [ ] `query_params`\n\n\u003cbr\u003e\n\n\n\n\n## Contributing\n\n - [Fork][github-fork], Enhance, Send PR\n - Lock issues with any bugs or feature requests\n - Implement something from Roadmap\n - Spread the word :heart:\n\n\u003cbr\u003e\n\n\n\n\n## License\n\nThis package is available as open source under the terms of the [MIT License][license].\n\n\u003cbr\u003e\n\n\n\n\n  [shield-version]:   https://img.shields.io/hexpm/v/better_params.svg\n  [shield-license]:   https://img.shields.io/hexpm/l/better_params.svg\n  [shield-downloads]: https://img.shields.io/hexpm/dt/better_params.svg\n  [shield-travis]:    https://img.shields.io/travis/sheharyarn/better_params/master.svg\n  [shield-inch]:      https://inch-ci.org/github/sheharyarn/better_params.svg?branch=master\n\n  [travis-ci]:        https://travis-ci.org/sheharyarn/better_params\n  [inch-ci]:          https://inch-ci.org/github/sheharyarn/better_params\n\n  [license]:          https://opensource.org/licenses/MIT\n  [hexpm]:            https://hex.pm/packages/better_params\n  [plug]:             https://github.com/elixir-lang/plug\n  [plug-params]:      https://hexdocs.pm/plug/Plug.Conn.html#module-fetchable-fields\n  [string-atom]:      https://hexdocs.pm/elixir/String.html#to_existing_atom/1\n\n  [docs]:             https://hexdocs.pm/better_params\n\n  [github-fork]:      https://github.com/sheharyarn/better_params/fork\n  [gh-issue-ddos]:    https://github.com/sheharyarn/better_params/issues/1\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsheharyarn%2Fbetter_params","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsheharyarn%2Fbetter_params","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsheharyarn%2Fbetter_params/lists"}