{"id":16659920,"url":"https://github.com/kumarshantanu/calfpath","last_synced_at":"2025-03-16T23:31:37.019Z","repository":{"id":32909832,"uuid":"36504757","full_name":"kumarshantanu/calfpath","owner":"kumarshantanu","description":"À la carte Ring request matching, routing and reverse-routing for Clojure/Script","archived":false,"fork":false,"pushed_at":"2021-02-03T16:25:32.000Z","size":409,"stargazers_count":33,"open_issues_count":0,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-27T15:08:09.752Z","etag":null,"topics":["clojure","clojurescript","ring","web-router"],"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/kumarshantanu.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","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":"2015-05-29T13:04:53.000Z","updated_at":"2024-05-31T07:57:39.000Z","dependencies_parsed_at":"2022-08-01T09:38:45.439Z","dependency_job_id":null,"html_url":"https://github.com/kumarshantanu/calfpath","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kumarshantanu%2Fcalfpath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kumarshantanu%2Fcalfpath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kumarshantanu%2Fcalfpath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kumarshantanu%2Fcalfpath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kumarshantanu","download_url":"https://codeload.github.com/kumarshantanu/calfpath/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243832793,"owners_count":20355147,"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","ring","web-router"],"created_at":"2024-10-12T10:27:07.308Z","updated_at":"2025-03-16T23:31:36.451Z","avatar_url":"https://github.com/kumarshantanu.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# calfpath\n\n[![Build Status](https://travis-ci.org/kumarshantanu/calfpath.svg)](https://travis-ci.org/kumarshantanu/calfpath)\n[![cljdoc badge](https://cljdoc.org/badge/calfpath/calfpath)](https://cljdoc.org/d/calfpath/calfpath)\n\nA Clojure/Script library for _à la carte_ (orthogonal) [Ring](https://github.com/ring-clojure/ring) request matching,\nrouting and reverse-routing.\n\n(_Calf path_ is a synonym for [Desire path](http://en.wikipedia.org/wiki/Desire_path).\n[The Calf-Path](http://www.poets.org/poetsorg/poem/calf-path) is a poem by _Sam Walter Foss_.)\n\n\n## Rationale\n\n- Ring has no built-in routing mechanism; Calfpath delivers this essential feature.\n- Orthogonality - match URI patterns, HTTP methods or anything in a Ring request.\n- Calfpath is fast (benchmarks included) - there is no cost to what you do not use.\n- Available as both dispatch macros and extensible, bi-directional, data-driven routes.\n\n\n## Usage\n\nLeiningen dependency: `[calfpath \"0.8.1\"]` (requires Clojure 1.8 or later, Java 7 or later)\n\nRequire namespace:\n```clojure\n(require '[calfpath.core  :refer [-\u003euri -\u003emethod\n                                  -\u003eget -\u003ehead -\u003eoptions -\u003epatch -\u003eput -\u003epost -\u003edelete]])\n(require '[calfpath.route :as r])\n```\n\n### Direct HTTP URI/method dispatch\n\nWhen you need to dispatch on URI pattern with convenient API:\n\n```clojure\n(defn handler\n  [request]\n  ;; -\u003euri is a macro that dispatches on URI pattern\n  (-\u003euri request\n    \"/user/:id*\" [id]  (-\u003euri request\n                         \"/profile/:type/\" [type] (-\u003emethod request\n                                                    :get {:status 200\n                                                          :headers {\"Content-Type\" \"text/plain\"}\n                                                          :body (format \"ID: %s, Type: %s\" id type)}\n                                                    :put {:status 200\n                                                          :headers {\"Content-Type\" \"text/plain\"}\n                                                          :body \"Updated\"})\n                         \"/permissions/\"   []     (-\u003emethod request\n                                                    :get {:status 200\n                                                          :headers {\"Content-Type\" \"text/plain\"}\n                                                          :body (str \"ID: \" id)}\n                                                    :put {:status 200\n                                                          :headers {\"Content-Type\" \"text/plain\"}\n                                                          :body (str \"Updated ID: \" id)}))\n    \"/company/:cid/dept/:did/\" [cid did] (-\u003eput request\n                                           {:status 200\n                                            :headers {\"Content-Type\" \"text/plain\"}\n                                            :body \"Data\"})\n    \"/this/is/a/static/route\"  []        (-\u003eput request\n                                           {:status 200\n                                            :headers {\"Content-Type\" \"text/plain\"}\n                                            :body \"output\"})))\n```\n\n### Data-driven routes\n\nCalfpath supports data-driven _routes_ where every route is a map of certain keys. Routes are easy to\nextend and re-purpose. See an example below (where route-handler has the same arity as a Ring handler):\n\n```clojure\n;; a route-handler is arity-1 (or arity-3 for async) fn, like a ring-handler\n(defn list-user-jobs\n  [{{:keys [user-id] :path-params} :as request}]\n  ...)\n\n(defn app-routes\n  \"Return a vector of routes.\"\n  []\n  [;; first route has a partial URI match,implied by a trailing '*'\n   {\"/users/:user-id*\" [{\"/jobs/\"        [{:get  list-user-jobs}\n                                          {:post assign-job}]}\n                        {[\"/permissions/\" :get] permissions-hanler}]}\n   {[\"/orders/:order-id/confirm/\" :post] confirm-order}\n   {\"/health/\"  health-status}\n   {\"/static/*\" (-\u003e (fn [_] {:status 400 :body \"No such file\"})      ; static files serving example\n                  ;; the following requires [ring/ring-core \"version\"] dependency in your project\n                  (ring.middleware.resource/wrap-resource \"public\")  ; render files from classpath\n                  (ring.middleware.file/wrap-file \"/var/www/public\") ; render files from filesystem\n                  (ring.middleware.content-type/wrap-content-type)\n                  (ring.middleware.not-modified/wrap-not-modified))}])\n\n;; create a Ring handler from given routes\n(def ring-handler\n  (-\u003e (app-routes)   ; return routes vector\n    r/compile-routes ; turn every map into a route by populating matchers in them\n    r/make-dispatcher))\n```\n\n\n## Documentation\n\nSee [documentation page](doc/intro.md) for concepts, examples and more features.\n\n\n## Development\n\nRunning tests:\n\n```shell\n$ lein do clean, test\n$ lein with-profile c08 test\n```\n\nRunning performance benchmarks:\n\n```shell\n$ lein do clean, perf-test\n$ lein with-profile c08,perf test  # on specified Clojure version\n```\n\n\n## License\n\nCopyright © 2015-2021 Shantanu Kumar\n\nDistributed under the Eclipse Public License either version 1.0 or (at\nyour option) any later version.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkumarshantanu%2Fcalfpath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkumarshantanu%2Fcalfpath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkumarshantanu%2Fcalfpath/lists"}