{"id":19858638,"url":"https://github.com/metosin/ring-http-response","last_synced_at":"2025-05-15T04:04:22.480Z","repository":{"id":13915187,"uuid":"16614317","full_name":"metosin/ring-http-response","owner":"metosin","description":"Handling HTTP Statuses with Clojure(Script)","archived":false,"fork":false,"pushed_at":"2025-02-16T10:10:12.000Z","size":195,"stargazers_count":151,"open_issues_count":2,"forks_count":25,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-05-15T04:03:22.345Z","etag":null,"topics":["clojure","clojurescript","http","metosin-stable","ring"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/metosin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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":"2014-02-07T12:43:05.000Z","updated_at":"2025-05-10T12:15:21.000Z","dependencies_parsed_at":"2025-03-24T17:10:21.950Z","dependency_job_id":null,"html_url":"https://github.com/metosin/ring-http-response","commit_stats":{"total_commits":135,"total_committers":17,"mean_commits":"7.9411764705882355","dds":0.4740740740740741,"last_synced_commit":"70944e94049bb0f17df63044c8598b131a414e80"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metosin%2Fring-http-response","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metosin%2Fring-http-response/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metosin%2Fring-http-response/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metosin%2Fring-http-response/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/metosin","download_url":"https://codeload.github.com/metosin/ring-http-response/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254270641,"owners_count":22042858,"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":["clojure","clojurescript","http","metosin-stable","ring"],"created_at":"2024-11-12T14:24:11.963Z","updated_at":"2025-05-15T04:04:22.435Z","avatar_url":"https://github.com/metosin.png","language":"Clojure","readme":"# ring-http-response ![Build Status](https://github.com/metosin/ring-http-response/actions/workflows/clojure.yml/badge.svg) [![cljdoc badge](https://cljdoc.xyz/badge/metosin/ring-http-response)](https://cljdoc.xyz/d/metosin/ring-http-response/CURRENT)\n\nHandling HTTP Statuses with Clojure(Script), originally ported from the awesome [Spray](http://spray.io/).\nMostly a drop-in-place replacement for `ring.util.response`.\n\n## Latest version\n\n[![Clojars Project](http://clojars.org/metosin/ring-http-response/latest-version.svg)](http://clojars.org/metosin/ring-http-response)\n\n## Usage\n\n### Generating HTTP responses\n\nFunctions take either a `body`, `url`, both or nothing as parameters in align to the [spec](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html).\n\n```clojure\n(require '[ring.util.http-response :refer :all])\n\n(continue)\n; {:status 100, :headers {}, :body \"\"}\n\n(ok \"body\")\n; {:status 200, :headers {}, :body \"body\"}\n\n(created \"url\" \"body\")\n; {:status 201, :headers {\"Location\" \"url\"}, :body \"body\"}\n\n(found \"url\")\n; {:status 302, :headers {\"Location\" \"url\"}, :body \"\"}\n```\n\n### Asserting HTTP responses\n\nAvailable for both Clojure \u0026 ClojureScript.\n\n```clojure\n(require '[ring.util.http-predicates :as predicates])\n\n(predicates/ok? {:status 200})\n; true\n\n(predicates/not-found? {:status 404})\n; true\n```\n\n### Status codes \u0026 documentation\n\nFor referring HTTP codes by name \u0026 for api docs like [Swagger](https://github.com/metosin/ring-swagger).\n\n```clojure\n(require '[ring.util.http-status :as status])\n\nstatus/ok\n; 200\n\nstatus/not-found\n; 404\n\n(status/get-name 404)\n; \"Not Found\"\n\n(status/get-description 404)\n; \"The requested resource could not be found but may be available again in the future.\"\n\n(status/status 404)\n; {:name \"Not Found\"\n;  :description \"The requested resource could not be found but may be available again in the future.\"}\n```\n\n### Throwing error responses\n\nAll response functions for HTTP error response have a exception throwing sibling with a bang in the name\n(`bad-request` \u0026 `bad-request!`). These functions throw the\nresponse wrapped in an `ExceptionInfo`.\n\n```clojure\n(require '[ring.util.http-response :as response])\n\n(response/bad-request \"fail\")\n; {:status 400, :headers {}, :body \"fail\"}\n\n(response/bad-request! \"fail\")\n; clojure.lang.ExceptionInfo: throw: {:type :ring.util.http-response/response, :response {:status 400, :headers {}, :body \"fail\"}}\n```\n\nThere is also a `throw!` function to throw any kind response in an exception.\n\n```clojure\n(require '[ring.util.http-response :as response])\n\n(response/throw! (response/header (response/bad-request \"body\") \"header\" \"value\"))\n; clojure.lang.ExceptionInfo: throw: {:type :ring.util.http-response/response, :response {:status 400, :headers {\"header\" \"value\"}, :body \"body\"}}\n```\n\n### Catching thrown HTTP responses\n\nMiddleware `ring.middleware.http-response/wrap-http-response` catches thrown HTTP-responses and returns the responses within.\nSee the [facts](https://github.com/metosin/ring-http-response/blob/master/test/ring/middleware/http_response_test.clj) for examples.\n\n## Migrating from ring.util.response\n1. add the dependency\n2. change your imports from `ring.util.response` to `ring.util.http-response`\n3. convert your responses to use the correct HTTP-terms:\n   - 200: `response` =\u003e `ok`\n   - 302: `redirect` =\u003e `found`\n   - 303: `redirect-after-post` =\u003e `see-other`\n4. enjoy\n\n`created` and `not-found` are same in both packages. Also rest of the public vars in `ring.util.response` are available via `ring.util.http-response`.\nThese include: `status`, `header`, `file-response`, `content-type`, `find-header`, `get-header`, `update-header`, `charset`, `set-cookie`, `response?`\n`resource-data`, `url-response` and `resource-response`.\n\n## Adding new HTTP status codes\n\nAll code is generated using [Mustache](https://mustache.github.io/) templates, see [user.clj](https://github.com/metosin/ring-http-response/blob/master/dev/user.clj).\n\n```\nlein repl\nuser=\u003e (generate!)\n```\n\n## Making a release\n\n- Update `CHANGELOG.md` and increment the version number in `project.clj`\n- Commit and push to Github\n- Create a Github release [here](https://github.com/metosin/ring-http-response/releases)\n  - Use the version number of the release for the tag name\n- The [Github Actions release workflow](.github/workflows/release.yml) should fire and deploy a release to clojars\n\n## License\nOriginal [code](https://github.com/spray/spray/blob/master/spray-http/src/main/scala/spray/http/StatusCode.scala): Copyright © 2011-2013 the spray project \u003chttp://spray.io\u003e.\n\nCopyright © 2014-2024 [Metosin Oy](http://www.metosin.fi)\n\nDistributed under the Eclipse Public License, the same as Clojure.\n","funding_links":[],"categories":["Clojure"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetosin%2Fring-http-response","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmetosin%2Fring-http-response","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetosin%2Fring-http-response/lists"}