Volver al ranking

metosin/compojure-api

Clojuremetosin.github.io/compojure-api/doc/

Sweet web apis with Compojure & Swagger

clojurerestapiswaggerschemaopenapihttpringclojure-specasyncmetosin-stable
Crecimiento de estrellas
Estrellas
1.1k
Forks
146
Crecimiento semanal
Issues
40
5001k
feb 2014mar 2018may 2022jul 2026
README

Compojure-api

Psst! If you're starting a new project, why not try out reitit?

Stuff on top of Compojure for making sweet web apis.

API Docs & Wiki

Latest version

Clojars Project

Latest non-alpha: [metosin/compojure-api "1.1.14"].

See CHANGELOG for details.

For information and help

Read the Version 1.0 Blog Post

Schema & Spec Coercion with 2.0.0

Check wiki for documentation

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 Api

(require '[compojure.api.sweet :refer :all])
(require '[ring.util.http-response :refer :all])

(def app
  (api
    (GET "/hello" []
      :query-params [name :- String]
      (ok {:message (str "Hello, " name)}))))

Hello World, async

(require '[compojure.api.sweet :refer :all])
(require '[clojure.core.async :as a])

(GET "/hello-async" []
  :query-params [name :- String]
  (a/go
    (a/<! (a/timeout 500))
    (ok {:message (str "Hello, " name)})))

* requires server to be run in async mode

Hello World, async & data-driven

(require '[compojure.api.sweet :refer :all])
(require '[clojure.core.async :as a])
(require '[schema.core :as s])

(context "/hello-async" []
  (resource
    {:get
     {:parameters {:query-params {:name String}}
      :responses {200 {:schema {:message String}}
                  404 {}
                  500 {:schema s/Any}}
      :handler (fn [{{:keys [name]} :query-params}]
                 (a/go
                   (a/<! (a/timeout 500))
                   (ok {:message (str "Hello, " name)})))}}))

* Note that empty body responses can be specified with {} or {:schema s/Any}

Hello World, async, data-driven & clojure.spec

(require '[compojure.api.sweet :refer :all])
(require '[clojure.core.async :as a])
(require '[clojure.spec.alpha :as s])

(s/def ::name string?)
(s/def ::message string?)

(context "/hello-async" []
  (resource
    {:coercion :spec
     :get {:parameters {:query-params (s/keys :req-un [::name])}
           :responses {200 {:schema (s/keys :req-un [::message])}}
           :handler (fn [{{:keys [name]} :query-params}]
                      (a/go
                        (a/<! (a/timeout 500))
                        (ok {:message (str "Hello, " name)})))}}))

Api with Schema & Swagger-docs

(require '[compojure.api.sweet :refer :all])
(require '[schema.core :as s])

(s/defschema Pizza
  {:name s/Str
   (s/optional-key :description) s/Str
   :size (s/enum :L :M :S)
   :origin {:country (s/enum :FI :PO)
            :city s/Str}})

(def app
  (api
    {:swagger
     {:ui "/api-docs"
      :spec "/swagger.json"
      :data {:info {:title "Sample API"
                    :description "Compojure Api example"}
             :tags [{:name "api", :description "some apis"}]
             :consumes ["application/json"]
             :produces ["application/json"]}}}

    (context "/api" []
      :tags ["api"]

      (GET "/plus" []
        :return {:result Long}
        :query-params [x :- Long, y :- Long]
        :summary "adds two numbers together"
        (ok {:result (+ x y)}))

      (POST "/echo" []
        :return Pizza
        :body [pizza Pizza]
        :summary "echoes a Pizza"
        (ok pizza)))))

swagger-api

More samples

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

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

Quick start for a new project

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-2019 Metosin Oy and contributors.

Distributed under the Eclipse Public License, see LICENSE.

Repositorios relacionados
penpot/penpot

Penpot: The open-source design platform for Product teams that need scalable collaboration.

ClojureMozilla Public License 2.0ux-designux-experience
penpot.app
57.1k3.8k
metabase/metabase

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

ClojureOtheranalyticsbusinessintelligence
metabase.com
48.3k6.7k
logseq/logseq

A privacy-first, open-source platform for knowledge management and collaboration. Download link: http://github.com/logseq/logseq/releases. roadmap: https://logseq.io/p/NX4mc_ggEV

ClojureGNU Affero General Public License v3.0knowledge-basegraph
logseq.com
44k2.7k
deeplearning4j/deeplearning4j

Suite of tools for deploying and training deep learning models using the JVM. Highlights include model import for keras, tensorflow, and onnx/pytorch, a modular and tiny c++ library for running math code and a java based math library on top of the core c++ library. Also includes samediff: a pytorch/tensorflow like library for running deep learn...

JavaMavenApache License 2.0javagpu
deeplearning4j.konduit.ai
14.2k3.8k
LightTable/LightTable

The Light Table IDE ⛺

ClojureMIT Licenseclojurescriptide
lighttable.com
11.7k911
kanaka/mal

mal - Make a Lisp

AssemblyOthermaldocker
10.7k2.7k
lk-geimfari/awesomo

Cool open source projects. Choose your project and get involved in Open Source development now.

GoGo ModulesCreative Commons Zero v1.0 Universalawesomeocaml
9.9k690
defold/defold

Defold is a completely free to use game engine for development of desktop, mobile and web games.

C++Otherdefoldgame-engine
defold.com
6.2k440
tonsky/datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS

ClojureEclipse Public License 1.0clojuredatabase
5.8k317
reagent-project/reagent

A minimalistic ClojureScript interface to React.js

ClojureMIT Licensereagentclojurescript
reagent-project.github.io
4.9k412
izhangzhihao/intellij-rainbow-brackets

🌈Rainbow Brackets for IntelliJ based IDEs/Android Studio/HUAWEI DevEco Studio/Fleet

KotlinOtherintellij-pluginrainbow
plugins.jetbrains.com/plugin/10080-rainbow-brackets
4.7k224
babashka/babashka

Native, fast starting Clojure interpreter for scripting

ClojureEclipse Public License 1.0clojureshell-scripting
babashka.org
4.6k273