{"id":16154745,"url":"https://github.com/idorobots/ring-routing","last_synced_at":"2025-03-18T20:30:19.666Z","repository":{"id":29441963,"uuid":"32978065","full_name":"Idorobots/ring-routing","owner":"Idorobots","description":"A tiny routing library for Ring emphasizing simplicity \u0026 readability.","archived":false,"fork":false,"pushed_at":"2017-06-02T17:14:24.000Z","size":59,"stargazers_count":2,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T12:04:15.772Z","etag":null,"topics":["clojure","macros","middleware","readability","ring"],"latest_commit_sha":null,"homepage":null,"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/Idorobots.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}},"created_at":"2015-03-27T09:33:35.000Z","updated_at":"2017-06-02T17:08:34.000Z","dependencies_parsed_at":"2022-09-07T10:51:51.972Z","dependency_job_id":null,"html_url":"https://github.com/Idorobots/ring-routing","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Idorobots%2Fring-routing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Idorobots%2Fring-routing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Idorobots%2Fring-routing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Idorobots%2Fring-routing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Idorobots","download_url":"https://codeload.github.com/Idorobots/ring-routing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243949723,"owners_count":20373647,"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","macros","middleware","readability","ring"],"created_at":"2024-10-10T01:18:49.662Z","updated_at":"2025-03-18T20:30:19.216Z","avatar_url":"https://github.com/Idorobots.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ring-routing [![Build Status](https://travis-ci.org/Idorobots/ring-routing.svg?branch=master)](https://travis-ci.org/Idorobots/ring-routing) [![Clojars Project](https://img.shields.io/clojars/v/ring-routing.svg)](https://clojars.org/ring-routing)\n\nA tiny Clojure library for [Ring](https://github.com/ring-clojure/ring) routing emphasizing simplicity \u0026 readability. `ring-routing` gives you fine-grained control over your middleware \u0026 routes - you can precisely tell how to dispatch incomming requests.\n\n## Usage\n\nSee the [API docs](https://idorobots.github.io/ring-routing/).\nHere's an example routes definition for a simple car API:\n\n``` clojure\n(ns car.core\n  (:require [car.middleware :as middleware]\n            [car.handlers :as app]\n            [ring.util.routing :refer [--\u003e --\u003c] :as route]))\n\n(def routes\n  (--\u003e middleware/wrap-parse-body\n       middleware/wrap-parse-cookies\n       middleware/wrap-log-request\n\n       (--\u003c (route/path \"/cars/:id/\")\n            (--\u003e middleware/wrap-polish-cars\n                 (--\u003c (route/method :get) app/get-car\n                      (route/method :post) app/post-car\n                      (route/method :delete) app/delete-car))\n\n            (route/path \"/parts/*\")\n            (--\u003c (route/path \"wheels/\") app/handle-wheels\n                 (route/path \"seats/\") app/handle-seats\n                 (route/path \"windows/\") app/install-linux))))\n```\n\n### Running middleware:\nUse route macro (`--\u003e`) to combine middleware and path definitions. The following middleware functions will run in order they are listed, so first the body will be parsed, next the cookies and then the request will be logged.\n\nMiddleware position is not constrained in any fashion, so if the request path matches `/cars/`, the `wrap-polish-cars` middleware will be run as well.\n\n\n``` clojure\n(--\u003e wrap-parse-body\n     wrap-parse-cookies\n     wrap-log-request\n\n     (--\u003e (route/path \"/cars/\")\n          wrap-polish-cars\n          handle-cars))\n```\n\n\n### Path parameters:\nYou can parameterize your paths and access path parameters useing the `:params` key in the Ring request map:\n\n``` clojure\n(defn get-car [{:keys [params]}]\n  ;; Do someting with (:id params)\n  )\n\n;; ...\n\n(--\u003e (route/path \"/cars/:id/\")\n     (route/method :get)\n     get-car)\n```\n\n### Multiple endpoints:\nUse fork macro (`--\u003c`) to define alternate paths, for example:\n\n``` clojure\n(--\u003c (route/path \"/cars/:id\") handle-cars\n     (route/path \"/parts/*\") handle-parts)\n```\n\n### Multiple endpoints with common prefix:\nSometimes you might want to add a common prefix to your API (for example for API versioning). Here's how to achieve that, note that you have to explicitly define your paths' wildcard:\n\n``` clojure\n(--\u003e (route/path \"/parts/*\")\n     (--\u003c (route/path \"wheels/\") handle-wheels\n          (route/path \"seats/\") handle-steats\n          (route/path \"windows/\") install-linux))\n```\n\n### Multiple methods on a single endpoint:\nDispatching on the request method works in a similar fashion:\n\n``` clojure\n(--\u003e (route/path \"/cars/:id\")\n     (--\u003c (route/method :get) get-car\n          (route/method :post) post-car\n          (route/method :delete) delete-car))\n```\n\n## License\n\nCopyright © 2015 kajtek@idorobots.org\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%2Fidorobots%2Fring-routing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidorobots%2Fring-routing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidorobots%2Fring-routing/lists"}