Skip to content

Commit 718f7ee

Browse files
authored
adds support for getting health information about a Typesense node (#46)
1 parent 291febb commit 718f7ee

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/typesense/api.clj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
(let [query-parameter-map (merge common-search-params opt-query-params)]
5353
(str uri "/multi_search" (util/map->url-parameter-string query-parameter-map))))
5454

55+
(defn- health-uri
56+
([uri]
57+
(str uri "/health")))
58+
5559
(defn create-collection-req
5660
[{:keys [uri key]} schema]
5761
{:uri (collection-uri uri)
@@ -236,3 +240,8 @@
236240
[{:keys [uri key]} collection-name synonym-name]
237241
{:uri (synonyms-uri uri collection-name synonym-name)
238242
:req {:headers {api-key-header-name key}}})
243+
244+
(defn health-req
245+
[{:keys [uri key]}]
246+
{:uri (health-uri uri)
247+
:req {:headers {api-key-header-name key}}})

src/typesense/client.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,10 @@
262262
(try-typesense-api
263263
(let [{:keys [uri req]} (api/delete-synonym-req settings collection-name synonym-name)]
264264
(util/http-response-json->map (http/delete uri req)))))
265+
266+
(defn health
267+
"Get health information about a Typesense node."
268+
[settings]
269+
(try-typesense-api
270+
(let [{:keys [uri req]} (api/health-req settings)]
271+
(util/http-response-json->map (http/get uri req)))))

test/typesense/api_test.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,10 @@
320320
exp {:uri "http://localhost:8108/collections/products/synonyms/coat-synonyms"
321321
:req {:headers {"X-TYPESENSE-API-KEY" "key"}}}]
322322
(is (= exp req))))
323+
324+
325+
(deftest health-test
326+
(let [req (sut/health-req settings)
327+
exp {:uri "http://localhost:8108/health"
328+
:req {:headers {"X-TYPESENSE-API-KEY" "key"}}}]
329+
(is (= exp req))))

test/typesense/client_test.clj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,4 +726,8 @@
726726
(let [id (-> (sut/list-api-keys settings) :keys first :id)
727727
exp {:id id}
728728
res (sut/delete-api-key! settings id)]
729-
(is (= exp res)))))
729+
(is (= exp res))))
730+
731+
(testing "Health"
732+
(let [res (sut/health settings)]
733+
(is (= res {:ok true})))))

0 commit comments

Comments
 (0)