22
33Stuff on top of [ Compojure] ( https://github.com/weavejester/compojure ) for making sweet web apis.
44
5- - [ API Docs] ( http://metosin.github.io/compojure-api/doc/ )
5+ - [ API Docs] ( http://metosin.github.io/compojure-api/doc/ ) & [ Wiki ] ( https://github.com/metosin/compojure-api/wiki )
66- [ Schema] ( https://github.com/Prismatic/schema ) for input & output data coercion
7- - [ Swagger 2.0 ] ( https ://github.com/wordnik/swagger-core/wiki ) for api documentation, via [ ring-swagger] ( https://github.com/metosin/ring-swagger )
7+ - [ Swagger] ( http ://swagger.io/ ) for api documentation, via [ ring-swagger] ( https://github.com/metosin/ring-swagger )
88- Extendable route DSL via [ metadata handlers] ( https://github.com/metosin/compojure-api/wiki/Creating-your-own-metadata-handlers )
9+ - Client negotiable formats: [ JSON] ( http://www.json.org/ ) , [ EDN] ( https://github.com/edn-format/edn ) , [ YAML] ( http://yaml.org/ ) & [ Transit] ( https://github.com/cognitect/transit-format ) (JSON & MessagePack)
910- Bi-directional routing
10- - Bundled middleware for common api behavior (exception mapping, data formats & serialization )
11+ - Bundled middleware for common api behavior (exception mapping, parameters & formats )
1112- Route macros for putting things together, including the [ Swagger-UI] ( https://github.com/wordnik/swagger-ui ) via [ ring-swagger-ui] ( https://github.com/metosin/ring-swagger-ui )
1213
1314## Latest version
1415
1516[ ![ Clojars Project] ( http://clojars.org/metosin/compojure-api/latest-version.svg )] ( http://clojars.org/metosin/compojure-api )
1617
17- ** NOTE** All codes in ` master ` are already against the upcoming ` 1.0.0 ` . Wiki is partially still for ` 0.24.5 ` .
18-
1918## For information and help
2019
2120### [ Check wiki for documentation] ( https://github.com/metosin/compojure-api/wiki )
@@ -27,23 +26,19 @@ Stuff on top of [Compojure](https://github.com/weavejester/compojure) for making
2726### Hello World
2827
2928``` clj
30- (ns example
31- (:require [compojure.api.sweet :refer :all ]
32- [ring.util.http-response :refer :all ]))
29+ (require '[compojure.api.sweet :refer :all ])
30+ (require '[ring.util.http-response :refer :all ])
3331
3432(defapi app
3533 (GET " /hello" []
3634 :query-params [name :- String]
3735 (ok {:message (str " Hello, " name)})))
3836```
39-
37+
4038### Api with Schema & Swagger-docs
41-
39+
4240 ``` clj
43- (ns example
44- (:require [compojure.api.sweet :refer :all ]
45- [ring.util.http-response :refer :all ]
46- [schema.core :as s]))
41+ (require '[schema.core :as s])
4742
4843(s/defschema Pizza
4944 {:name s/Str
@@ -52,35 +47,36 @@ Stuff on top of [Compojure](https://github.com/weavejester/compojure) for making
5247 :origin {:country (s/enum :FI :PO )
5348 :city s/Str}})
5449
55- (defapi app
56- {:swagger
57- {:ui " /api-docs"
58- :spec " /swagger.json"
59- :data {:info {:title " Sample API"
60- :description " Compojure Api example" }
61- :tags [{:name " api" , :description " some apis" }]}}}
62-
63- (context " /api" []
64- :tags [" api" ]
65-
66- (GET " /plus" []
67- :return {:result Long}
68- :query-params [x :- Long, y :- Long]
69- :summary " adds two numbers together"
70- (ok {:result (+ x y)}))
71-
72- (POST " /echo" []
73- :return Pizza
74- :body [pizza Pizza]
75- :summary " echoes a Pizza"
76- (ok pizza))))
50+ (def app
51+ (api
52+ {:swagger
53+ {:ui " /api-docs"
54+ :spec " /swagger.json"
55+ :data {:info {:title " Sample API"
56+ :description " Compojure Api example" }
57+ :tags [{:name " api" , :description " some apis" }]}}}
58+
59+ (context " /api" []
60+ :tags [" api" ]
61+
62+ (GET " /plus" []
63+ :return {:result Long}
64+ :query-params [x :- Long, y :- Long]
65+ :summary " adds two numbers together"
66+ (ok {:result (+ x y)}))
67+
68+ (POST " /echo" []
69+ :return Pizza
70+ :body [pizza Pizza]
71+ :summary " echoes a Pizza"
72+ (ok pizza)))))
7773```
7874
7975![ swagger-api] ( https://raw.githubusercontent.com/wiki/metosin/compojure-api/swagger-api.png )
8076
8177## More samples
8278
83- This repo contains [ a sample application ] ( ./examples/src/examples/thingie.clj ) .
79+ https://github.com/metosin/compojure-api/tree/master/examples
8480
8581To try it yourself, clone this repository and do either:
8682
@@ -101,6 +97,6 @@ lein new compojure-api my-api +clojure-test
10197
10298## License
10399
104- Copyright © 2014-2015 [ Metosin Oy] ( http://www.metosin.fi )
100+ Copyright © 2014-2016 [ Metosin Oy] ( http://www.metosin.fi )
105101
106102Distributed under the Eclipse Public License, the same as Clojure.
0 commit comments