{"id":13509066,"url":"https://github.com/malomohq/accent","last_synced_at":"2025-04-10T03:54:53.011Z","repository":{"id":19768344,"uuid":"87856586","full_name":"malomohq/accent","owner":"malomohq","description":"Dynamically convert the case of your JSON API keys","archived":false,"fork":false,"pushed_at":"2024-07-09T00:58:03.000Z","size":239,"stargazers_count":44,"open_issues_count":3,"forks_count":13,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T03:54:46.462Z","etag":null,"topics":["elixir-lang","made-by-malomo","phoenix","plug"],"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/malomohq.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-04-10T20:52:42.000Z","updated_at":"2025-03-11T07:41:49.000Z","dependencies_parsed_at":"2024-01-26T05:06:58.491Z","dependency_job_id":"c2af635b-d733-49db-95ff-b2440e81ddb1","html_url":"https://github.com/malomohq/accent","commit_stats":{"total_commits":163,"total_committers":9,"mean_commits":18.11111111111111,"dds":0.6687116564417178,"last_synced_commit":"96cffbae65cd5de10b6847ccf15f63c973b4ac12"},"previous_names":["sticksnleaves/accent"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malomohq%2Faccent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malomohq%2Faccent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malomohq%2Faccent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malomohq%2Faccent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/malomohq","download_url":"https://codeload.github.com/malomohq/accent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248154999,"owners_count":21056542,"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-lang","made-by-malomo","phoenix","plug"],"created_at":"2024-08-01T02:01:02.547Z","updated_at":"2025-04-10T03:54:52.989Z","avatar_url":"https://github.com/malomohq.png","language":"Elixir","funding_links":[],"categories":["REST and API"],"sub_categories":[],"readme":"# Accent\n\n![](https://github.com/malomohq/accent/workflows/ci/badge.svg)\n\n## Installation\n\nThis package can be installed by adding `accent` to your list of dependencies in\n`mix.exs`:\n\n```elixir\ndef deps do\n  [{:accent, \"~\u003e 1.1\"}]\nend\n```\n\nPlease note that you will need to provide `accent` with a JSON codec. Both\n[`poison`](https://github.com/devinus/poison) and\n[`jason`](https://github.com/michalmuskala/jason) are supported.\n\n## Usage\n\nThis project provides two plugs for handling the conversion of JSON keys to\ndifferent cases: `Accent.Plug.Request` and `Accent.Plug.Response`\n\n### `Accent.Plug.Request`\n\nTransforms the keys of an HTTP request's params to the same or a different\ncase.\n\nYou can specify what case to convert keys to by passing in a `:transformer`\noption.\n\nAccent supports the following transformers out of the box:\n\n* `Accent.Case.Camel` (e.g. `camelCase`)\n* `Accent.Case.Pascal` (e.g. `PascalCase`)\n* `Accent.Case.Snake` (e.g. `snake_case`)\n\nIf no transformer is provided then `Accent.Case.Snake` will be\nused.\n\nPlease note that this plug will need to be executed after the request has\nbeen parsed.\n\n**Example**\n\nGiven this request:\n\n```\ncurl -X POST https://yourapi.com/endpoints \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"hello\": \"Accent\"}'\n```\n\na router with this configuration:\n\n```elixir\nplug Plug.Parsers, parsers: [:urlencoded, :multipart, :json],\n                   pass: [\"*/*\"],\n                   json_decoder: Jason\n\nplug Accent.Plug.Request\n```\n\ncould expect to receive a `conn.params` value of:\n\n```elixir\n%{\"hello\" =\u003e \"Accent\"}\n```\n\n### `Accent.Plug.Response`\n\nTransforms the keys of an HTTP response to the case requested by the client.\n\nA client can request what case the keys are formatted in by passing the case\nas a header in the request. By default the header key is `Accent`. If the\nclient does not request a case or requests an unsupported case then a default\ncase defined by `:default_case` will be used. If no default case is provided\nthen no conversion will happen. By default the supported cases are `camel`,\n`pascal` and `snake`.\n\n## Options\n\n* `:default_case` - module used to case the response when the client does not\n  request a case or requests an unsupported case. When not provided then no\n  conversation will happen for the above scenarios. Defaults to `nil`.\n* `:header` - the HTTP header used to determine the case to convert the\n  response body to before sending the response (default: `Accent`)\n* `:json_codec` - module used to encode and decode JSON. The module is\n  expected to define `decode/1` and `encode!/1` functions (required).\n* `:supported_cases` - map that defines what cases a client can request. By\n  default `camel`, `pascal` and `snake` are supported.\n\n**Example**\n\n```\nplug Accent.Plug.Response, default_case: Accent.Case.Snake,\n                           header: \"x-accent\",\n                           supported_cases: %{\"pascal\" =\u003e Accent.Case.Pascal},\n                           json_codec: Jason\n```\n\nGiven this request:\n\n```\ncurl -X POST https://yourapi.com/endpoints \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Accent: camel\" \\\n  -d '{\"hello\": \"Accent\"}'\n```\n\nwith this router:\n\n```elixir\ndefmodule MyAPI.Router do\n  use Plug.Router\n\n  plug Accent.Plug.Response, json_codec: Jason\n\n  post \"/\" do\n    send_resp(conn, 200, Jason.encode!(%{hello_back: \"Anthony\"}))\n  end\nend\n```\n\na client could expect a JSON response of:\n\n```json\n{\n  \"helloBack\": \"Anthony\"\n}\n```\n\n## Contributors\n\nA special thanks to all of our contributors!\n\n* [@anthonator](https://github.com/anthonator)\n* [@maxsalven](https://github.com/maxsalven)\n* [@szajbus](https://github.com/szajbus)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalomohq%2Faccent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmalomohq%2Faccent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalomohq%2Faccent/lists"}