From f1b9d5e3168c5d38180f4c4da7cb10d284ca6bdd Mon Sep 17 00:00:00 2001 From: Guillaume Buisson Date: Thu, 21 May 2015 15:35:11 +0200 Subject: [PATCH] added example using compojure api --- .gitignore | 1 + examples/project.clj | 15 ++++++++++++ examples/src/handler.clj | 41 +++++++++++++++++++++++++++++++++ project.clj | 2 +- src/clj_druid/schemas/query.clj | 9 ++++++++ 5 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 examples/project.clj create mode 100644 examples/src/handler.clj diff --git a/.gitignore b/.gitignore index 4d63e85..4b13173 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +examples/target target .lein-failures .lein-history diff --git a/examples/project.clj b/examples/project.clj new file mode 100644 index 0000000..0c2930f --- /dev/null +++ b/examples/project.clj @@ -0,0 +1,15 @@ +(defproject y42/clj-druid-examples "0.2.3" + :description "clj-druid-examples" + :dependencies [[org.clojure/clojure "1.6.0"] + [clj-time "0.9.0"] ;; needed as `lein ring` is broken + [metosin/compojure-api "0.20.3"] + [metosin/ring-http-response "0.6.1"] + [metosin/ring-swagger-ui "2.1.1-M2"] + [y42/clj-druid "0.2.3"]] + :ring {:handler handler/app} + :uberjar-name "examples.jar" + :uberwar-name "examples.war" + :profiles {:uberjar {:resource-paths ["swagger-ui"] + :aot :all} + :dev {:dependencies [[javax.servlet/servlet-api "2.5"]] + :plugins [[lein-ring "0.9.4"]]}}) diff --git a/examples/src/handler.clj b/examples/src/handler.clj new file mode 100644 index 0000000..7b941d6 --- /dev/null +++ b/examples/src/handler.clj @@ -0,0 +1,41 @@ +(ns handler + (:require [compojure.api.sweet :refer :all] + [ring.util.http-response :refer :all] + [clj-druid.schemas.query :refer :all])) + +(defapi app + (swagger-ui) + (swagger-docs + {:info {:title "clj-druid + Compojure API" + :description "clj-druid sample application"}}) + (context* "/druid" [] + :tags ["query"] + (POST* "/groupBy" [] + :body [q groupBy] + :summary "Issue a groupBy query" + (ok true)) + + (POST* "/topN" [] + :body [q topN] + :summary "Issue a topN query" + (ok true)) + + (POST* "/timeseries" [] + :body [q timeseries] + :summary "Issue a timeseries query" + (ok true)) + + (POST* "/search" [] + :body [q search] + :summary "Issue a search query" + (ok true)) + + (POST* "/timeBoundary" [] + :body [q timeBoundary] + :summary "Issue a timeBoundary query" + (ok true)) + + (POST* "/segmentMetadata" [] + :body [q segmentMetadata] + :summary "Issue a segmentMetadata query" + (ok true)))) diff --git a/project.clj b/project.clj index 9bfdfc8..820d714 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject y42/clj-druid "0.2.2" +(defproject y42/clj-druid "0.2.3" :description "Clojure library for Druid.io" :url "http://github.com/y42/clj-druid" :license {:name "MIT" diff --git a/src/clj_druid/schemas/query.clj b/src/clj_druid/schemas/query.clj index 134feaa..1a13b55 100644 --- a/src/clj_druid/schemas/query.clj +++ b/src/clj_druid/schemas/query.clj @@ -95,6 +95,15 @@ (s/optional-key :bound) (s/enum :minTime :maxTime) (s/optional-key :context) context}) +(s/defschema query + (s/either groupBy + search + segmentMetadata + timeBoundary + timeseries + topN + select)) + (def queries {:groupBy groupBy :search search :segmentMetadata segmentMetadata