{"id":13508294,"url":"https://github.com/pkinney/explode","last_synced_at":"2025-10-21T19:01:20.054Z","repository":{"id":62429387,"uuid":"65240611","full_name":"pkinney/explode","owner":"pkinney","description":"An easy utility for responding with standard HTTP/JSON error payloads in Plug- and Phoenix-based applications","archived":false,"fork":false,"pushed_at":"2023-05-31T20:57:21.000Z","size":164,"stargazers_count":44,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-01T08:32:57.544Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/pkinney.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}},"created_at":"2016-08-08T21:26:53.000Z","updated_at":"2024-04-29T21:47:10.000Z","dependencies_parsed_at":"2022-11-01T20:06:00.484Z","dependency_job_id":"48a4a362-44a6-4b6f-a2f5-4e0906704eb4","html_url":"https://github.com/pkinney/explode","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/pkinney%2Fexplode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkinney%2Fexplode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkinney%2Fexplode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkinney%2Fexplode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pkinney","download_url":"https://codeload.github.com/pkinney/explode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246314011,"owners_count":20757450,"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":[],"created_at":"2024-08-01T02:00:51.004Z","updated_at":"2025-10-21T19:01:19.950Z","avatar_url":"https://github.com/pkinney.png","language":"Elixir","funding_links":[],"categories":["HTTP"],"sub_categories":[],"readme":"# Explode\n\n[![CI](https://github.com/pkinney/explode/actions/workflows/ci.yaml/badge.svg)](https://github.com/pkinney/explode/actions/workflows/ci.yaml)\n[![Hex.pm](https://img.shields.io/hexpm/v/explode.svg)](https://hex.pm/packages/explode)\n\nAn easy utility for responding with standard HTTP/JSON error payloads in Plug- and Phoenix-based applications.\n\nThis project is heavily influenced by Hapi's Boom module [https://github.com/hapijs/boom]\n\n## Installation\n\n```elixir\ndefp deps do\n  [{:explode, \"~\u003e 1.0.0\"}]\nend\n```\n\n## Usage\n\nTurns\n\n```elixir\nconn\n|\u003e put_resp_content_type(\"application/json\")\n|\u003e send_resp(:unauthorized, \"{\\\"statusCode\\\":403,\\\"error\\\":\\\"Forbidden\\\",\\\"message\\\":\\\"You are not authorized to view this resource\\\"}\")\n|\u003e halt\n```\n\ninto\n\n```elixir\nconn |\u003e Explode.with(403, \"You are not authorized to view this resource\")\n\n# or\n\nconn |\u003e Explode.forbidden(\"You are not authorized to view this resource\")\n```\n\n### Error Responses\n\nExplode sets the status code of the response and normalizes errors into a single structure:\n\n```json\n{\n  \"statusCode\": 403,\n  \"error\": \"Not Authorized\",\n  \"message\": \"You are not authorized to view this resource\"\n}\n```\n\n### JSON API\n\nIn order to be compliant with the JSON API spec (http://jsonapi.org/format/#errors),\nif the request headers in the `conn` object passed to Explode includes `Accept`\nof `\"application/vnd.api+json\"`, then the error response will be formatted to match\nthe JSON API Error Object spect (http://jsonapi.org/format/#errors). Additionally,\nthe `Content-Type` header of the response will also be set to\n`\"application/vnd.api+json\"`.\n\n```json\n{\n  \"errors\": [\n    {\n      \"status\": 403,\n      \"title\": \"Forbidden\",\n      \"detail\": \"You are not authorized to view this resource\"\n    }\n  ]\n}\n```\n\n### Ecto Changeset\n\nExplode will also accept an `Ecto.Changeset` struct instead of a message. This allows a Phoenix application to\ndirectly hand a Changeset to Explode without having to do an traversal of errors.\n\n```elixir\nchangeset = %Ecto.Changeset{\n  action: :insert,\n  types: %{},\n  changes: %{first_name: \"John\", last_name: \"Smith\", password: \"foo\"},\n  errors: [\n    password: {\"should be at least %{count} character(s)\", [count: 5, validation: :length, min: 5]},\n    email: {\"can't be blank\", [validation: :required]}],\n  valid?: false,\n  data: %User{}\n}\n\nExplode.with(conn, changeset)\n```\n\nwill result in the following error response:\n\n```json\n{\n  \"statusCode\": 400,\n  \"error\": \"Bad Request\",\n  \"message\": \"`email` can't be blank, `password` should be at least 5 character(s)\"\n}\n```\n\n### Bring your own JSON encoder\n\nExplode by default with use [Poison](https://github.com/devinus/poison) as the JSON encoding library. If you want to change that out, you can do so in `config.exs`\n\n```elixir\nconfig(:explode, :json_library, Jason)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkinney%2Fexplode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpkinney%2Fexplode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkinney%2Fexplode/lists"}