Skip to content

yiwang/compojure-api

 
 

Repository files navigation

Compojure-api Build Status Downloads Dependencies Status

Stuff on top of Compojure for making sweet web apis.

Latest version

Clojars Project

NOTE All codes in master are already against the upcoming 1.0.0. README and wiki are for the latest stabile version.

For information and help

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).

Examples

Hello World

(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)})))

Api with Schema & Swagger-docs

(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))))

swagger-api

More samples

This repo contains a sample application.

To try it yourself, clone this repository and do either:

  1. lein run
  2. lein repl & (go)

Quick start for new project

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

License

Copyright © 2014-2015 Metosin Oy

Distributed under the Eclipse Public License, the same as Clojure.

About

Swaggered Compojure Web Apis

Resources

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Clojure 99.5%
  • Shell 0.5%