{"id":14977576,"url":"https://github.com/linktosriram/clojure-spring-guide","last_synced_at":"2025-10-28T04:31:36.607Z","repository":{"id":84228321,"uuid":"111189505","full_name":"linktosriram/clojure-spring-guide","owner":"linktosriram","description":"Guidelines for using Clojure with Spring Framework","archived":false,"fork":false,"pushed_at":"2017-11-18T10:18:25.000Z","size":3,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T11:24:54.646Z","etag":null,"topics":["annotations","clojure","clojure-spring-guide","java","spring","spring-boot","spring-framework"],"latest_commit_sha":null,"homepage":"https://linktosriram.github.io/clojure-spring-guide/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linktosriram.png","metadata":{"files":{"readme":"README.md","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-18T08:35:13.000Z","updated_at":"2024-10-24T21:11:47.000Z","dependencies_parsed_at":"2023-05-24T01:30:20.630Z","dependency_job_id":null,"html_url":"https://github.com/linktosriram/clojure-spring-guide","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"a09882b8aadacefe7e5becc0f6147e62a6a25296"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linktosriram%2Fclojure-spring-guide","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linktosriram%2Fclojure-spring-guide/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linktosriram%2Fclojure-spring-guide/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linktosriram%2Fclojure-spring-guide/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linktosriram","download_url":"https://codeload.github.com/linktosriram/clojure-spring-guide/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238597386,"owners_count":19498396,"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":["annotations","clojure","clojure-spring-guide","java","spring","spring-boot","spring-framework"],"created_at":"2024-09-24T13:55:56.269Z","updated_at":"2025-10-28T04:31:31.333Z","avatar_url":"https://github.com/linktosriram.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# clojure-spring-guide\nGuidelines for using Clojure with Spring Framework\n\n[Clojure Style Guide](https://goo.gl/WWfjB)\n\n# Controllers\n\n* Use [@RestController](https://goo.gl/DpiwnS)\n* Use [@GetMapping](https://goo.gl/Y1tX55), [@PostMapping](https://goo.gl/BsajaA) family of annotations over traditional [@RequestMapping](https://goo.gl/naenPG) ones\n* Consume and Produce [MediaType.APPLICATION_JSON_UTF8_VALUE](https://goo.gl/US1rUY)\n* When returning clojure data structures out of controllers, use [cheshire](https://goo.gl/TCNat)\n```clojure\n(ns ...\n  (:require [cheshire.core :as json]))\n```\n\nand then return using\n\n```clojure\n(json/generate-string {:a 1 :b 2})\n```\n\n* When using annotations like [@PathVariable](https://goo.gl/b5XdMB), [@RequestParam](https://goo.gl/nm7ZiD) etc., specify the `value` attribute as the debugging information is not available. The value attribute can be dash-case.\nOtherwise the following error will occur: `Name for argument type [java.lang.String] not available, and parameter name information not found in class file either.`\n\n* We cannot require another namespace or import a class in `(ns :gen-class )`. The code emitted by ns macro calls `:gen-class` before calling any of the `:require` or `:import`.\nThus the required namespace/class or not compiled when `:gen-class` is called. We can use fully qualified names to solve this, but that would be ugly.\nA Better solution is to call `(gen-class ...)` after `(ns ...)`\n\n* Method arguments types and return types still need to be fully qualified (except java.lang.*)\n\n* Method names should be camelCase instead of dash-case due to Java restrictions\n\n* If you prefer, you can return [CompletableFuture](https://goo.gl/QQ6uv2) from the controller method to be asynchronous with the following macro\n\n```clojure\n(ns ...\n  (:import (java.util.concurrent CompletableFuture)\n           (java.util.function Supplier)))\n           \n(defmacro async\n  \"Wraps the given `body` inside a CompletableFuture.\"\n  [\u0026 body]\n  `(CompletableFuture/supplyAsync\n     (reify\n       Supplier\n       ~(list 'get '[this] (cons 'do body)))))\n```\n\nand then use it like\n\n```clojure\n(async\n  (println \"Async Controller method\")\n  (+ 3 5))\n```\n\n## Complete Example\n\n```clojure\n(ns com.clojurespring.controller\n  (:require [cheshire.core :as json])\n  (:import (org.springframework.web.bind.annotation RestController GetMapping PathVariable)))\n\n(gen-class\n  :name ^{RestController {}} com.clojurespring.SampleController\n  :methods [[^{GetMapping {:value    [\"/hello\"]\n                           :produces [\"application/json;charset=UTF-8\"}}\n                           hello [^{PathVariable {:value \"name\"}} String] java.util.concurrent.Future]])\n\n(defn -hello\n  [this name]\n  (async\n    (println \"Inside async controller...\")\n    (json/generate-string {:a       1\n                           :message (str \"Hello \" name \" from Clojure controller\"))))\n```\n### Request\n```bash\ncurl -X GET -H \"Accept: application/json;charset=UTF-8\" \"http://server.name/hello/rich\"\n```\n\n### Response\n```json\n{\n  \"a\": 1,\n  \"message\": \"Hello rich from Clojure controller\"\n}\n```\n\n# Contributing\n\nNothing written in this guide is set in stone. It's my desire to work together with everyone interested in Clojure coding style, so that we could ultimately create a resource that will be beneficial to the entire Clojure community.\n\nFeel free to open tickets or send pull requests with improvements. Thanks in advance for your help!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinktosriram%2Fclojure-spring-guide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinktosriram%2Fclojure-spring-guide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinktosriram%2Fclojure-spring-guide/lists"}