Stuff on top of Compojure for making sweet web apis.
- API Docs
- Schema for input & output data coercion
- Swagger 2.0 for api documentation, via ring-swagger
- Extendable route DSL via metadata handlers
- Bi-directional routing
- Bundled middleware for common api behavior (exception mapping, data formats & serialization)
- Route macros for putting things together, including the Swagger-UI via ring-swagger-ui
Clojurians slack (join) has a channel #ring-swagger for talk about any libraries using Ring-swagger. You can also ask questions about Compojure-api and Ring-swagger on other channels at Clojurians Slack or at #clojure on Freenode IRC (mention compojure-api
or ring-swagger
to highlight us).
(ns example
(:require [compojure.api.sweet :refer :all]
[ring.util.http-response :refer :all]))
(defapi app
(GET* "/hello" []
:query-params [name :- String]
(ok {:message (str "Hello, " name)})))
(ns example
(:require [compojure.api.sweet :refer :all]
[ring.util.http-response :refer :all]
[schema.core :as s]))
(s/defschema Pizza
{:name s/Str
:size (s/enum :L :M :S)
:origin {:country (s/enum :FI :PO)
:city s/Str}})
(defapi app
(swagger-ui)
(swagger-docs
{:info {:title "My Swagger API"
:description "Compojure Api example"}
:tags [{:name "api", :description "sample api"}]})
(context* "/api" []
:tags ["api"]
(GET* "/hello" []
:query-params [name :- String]
(ok {:message (str "Hello, " name)}))
(POST* "/pizza" []
:return Pizza
:body [pizza Pizza]
:summary "echoes a pizza"
(ok pizza))))
This repo contains a sample application.
To try it yourself, clone this repository and do either:
lein run
lein repl
&(go)
Clone the examples-repository.
Use a Leiningen template, with or without tests:
lein new compojure-api my-api
lein new compojure-api my-api +midje
lein new compojure-api my-api +clojure-test
Copyright © 2014-2015 Metosin Oy
Distributed under the Eclipse Public License, the same as Clojure.