{"id":32192108,"url":"https://github.com/tailrecursion/ring-edn","last_synced_at":"2025-12-12T01:24:24.809Z","repository":{"id":4813319,"uuid":"5966956","full_name":"tailrecursion/ring-edn","owner":"tailrecursion","description":"EDN handler for Ring","archived":false,"fork":false,"pushed_at":"2018-01-15T19:29:13.000Z","size":167,"stargazers_count":64,"open_issues_count":2,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-09-30T18:20:42.275Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"square/java-code-styles","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tailrecursion.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-09-26T14:23:14.000Z","updated_at":"2025-03-13T18:02:53.000Z","dependencies_parsed_at":"2022-09-01T01:21:33.772Z","dependency_job_id":null,"html_url":"https://github.com/tailrecursion/ring-edn","commit_stats":null,"previous_names":["fogus/ring-edn"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/tailrecursion/ring-edn","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tailrecursion%2Fring-edn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tailrecursion%2Fring-edn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tailrecursion%2Fring-edn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tailrecursion%2Fring-edn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tailrecursion","download_url":"https://codeload.github.com/tailrecursion/ring-edn/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tailrecursion%2Fring-edn/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280365594,"owners_count":26318385,"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","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-10-22T01:58:33.938Z","updated_at":"2025-10-22T01:58:37.600Z","avatar_url":"https://github.com/tailrecursion.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ring-edn\n\nA [Ring](https://github.com/mmcgrana/ring) middleware that augments :params by parsing a request body as [Extensible Data Notation](https://github.com/edn-format/edn) (EDN).\n\n## Where\n\n  * [Source repository](https://github.com/fogus/ring-edn) *-- patches welcomed*\n\n## Usage\n\n### Leiningen\n\nIn your `:dependencies` section add the following:\n\n    [fogus/ring-edn \"0.3.0\"]\n\n### Ring\n\n*the [examples directory of the ring-edn project](http://github.com/fogus/ring-edn/tree/master/examples/awe) contains the source for the following*\n\nTo use this middleware using Ring and [Compojure](https://github.com/weavejester/compojure), create a new Leiningen project with a `project.clj` file of the form:\n\n```clojure\n(defproject awesomeness \"0.0.1\"\n  :description \"true power awesomeness\"\n  :dependencies [[org.clojure/clojure \"1.6.0\"]\n                 [ring \"1.0.2\"]\n                 [compojure \"1.0.1\"]\n                 [fogus/ring-edn \"0.3.0\"]]\n  :main awesome-app)\n```\n\nNext, create a file in `src` called `my_awesome_service.clj` with the following:\n\n```clojure\n(ns my-awesome-service\n  (:use compojure.core)\n  (:use ring.middleware.edn))\n\n(defn generate-response [data \u0026 [status]]\n  {:status (or status 200)\n   :headers {\"Content-Type\" \"application/edn\"}\n   :body (pr-str data)})\n  \n(defroutes handler\n  (GET \"/\" []\n       (generate-response {:hello :cleveland}))\n\n  (PUT \"/\" [name]\n       (generate-response {:hello name})))\n\n(def app\n  (-\u003e handler\n      wrap-edn-params))\n```\n\nAnd finally, create another file in `src` named `awesome_app.clj` with the following:\n\n```clojure\n(ns awesome-app\n  (:use ring.adapter.jetty)\n  (:require [my-awesome-service :as awe]))\n\n(defn -main\n  [\u0026 args]\n  (run-jetty #'awe/app {:port 8080}))\n```\n\n### Using custom types\n\nEDN offers extensible types through\n[tagged literals](https://github.com/edn-format/edn#tagged-elements)\nand `ring-edn` can read those types from the incoming requests.\nAs an example, let's add `uri` to EDN. In our Clojure program\nit will be represented by `java.net.URI` but in other platforms it\nmight be represented differently, i.e `goog.Uri` in ClojureScript. To\nuse a new type, we need to define a reader (takes a string and returns\nour representation) and a printer (takes our representation and writes\nit as a string). The printer determines the tagged literal and it is\nimplemented as a multimethod of `clojure.core/print-method`. We might\nbe tempted to use `#uri` for the tagged literal but it needs to be\nnamespaced in case an application needs to deal with multiple `uri`\nrepresentations. Therefore we will use `#my-app/uri`:\n\n```clj\n(ns my-app.uri\n  (:import (java.net URI)))\n\n(defn read-uri [s]\n  (URI. s))\n\n(defmethod print-method java.net.URI [this w]\n  (.write w \"#my-app/uri \\\"\")\n  (.write w (.toString this))\n  (.write w \"\\\"\"))\n```\n\nNow we indicate `wrap-edn-params` that whenever it finds `#my-app/uri`\nit should read the expression that follows with `read-uri`:\n\n```\n(def app\n  (-\u003e handler\n      (wrap-edn-params {:readers {'my-app/uri #'my-app.uri/read-uri}})))\n```\n\nOther options besides `:readers` can be passed to `wrap-edn-params`\nwhich are forwarded to `clojure.edn/read-string` as defined\n[here](https://clojure.github.io/clojure/clojure.edn-api.html).\n\n\n### Testing\n\nRun this app in your console with `lein run` and test with `curl` using the following:\n\n```sh\n$ curl -X GET http://localhost:8080/\n\n#=\u003e {:hello :cleveland}\n\n$ curl -X PUT -H \"Content-Type: application/edn\" \\ \n  -d '{:name :barnabas}' \\\n  http://localhost:8080/ \n\n#=\u003e {:hello :barnabas}%\n```\n\nYou can also run the test suite with `lein test`.\n\n## Acknowledgment(s)\n\nThanks to [Mark McGranaghan](http://markmcgranaghan.com/) for his work on Ring and [ring-json-params](https://github.com/mmcgrana/ring-json-params) on which this project was based.  An additional thanks to Sebastian Bensusan for his high-quality patches.\n\n## License\n\nCopyright (C) 2012-2015 Fogus\n\nDistributed under the Eclipse Public License, the same as Clojure.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftailrecursion%2Fring-edn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftailrecursion%2Fring-edn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftailrecursion%2Fring-edn/lists"}