Skip to content

Instantly share code, notes, and snippets.

@ikitommi
Last active September 28, 2015 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikitommi/977cc9fcf037770d6687 to your computer and use it in GitHub Desktop.
Save ikitommi/977cc9fcf037770d6687 to your computer and use it in GitHub Desktop.
JSON Arrays with Compojure-api
(ns kikka.handler
(:require [compojure.api.sweet :refer :all]
[ring.util.http-response :refer :all]
[schema.core :as s]))
(defapi app
(swagger-ui)
(swagger-docs)
(POST* "/body" []
:return [s/Int]
:body [body [s/Int]]
(ok body)))

create a project:

lein new compojure-api kikka
cd kikka
; edit handler.clj
lein ring server

test it:

curl -H 'Content-Type: application/json' -X POST -d '[1,2,3]'
; [1,2,3]

curl -H 'Content-Type: application/json' -X POST -d '[1,2,"abba"]' http://localhost:3000/body
; {"errors":[null,null,"(not (integer? \"abba\"))"]}

see metosin/ring-swagger#55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment