diff --git a/src/fluree/server/handler.clj b/src/fluree/server/handler.clj index b8902b0..3af3c6a 100644 --- a/src/fluree/server/handler.clj +++ b/src/fluree/server/handler.clj @@ -198,6 +198,10 @@ :coercion ^:replace history-coercer :handler #'ledger/history}) +(def info-endpoint + {:summary "Ledger status and statistics" + :handler #'ledger/info}) + (def fallback-handler (let [swagger-ui-handler (swagger-ui/create-swagger-ui-handler {:path "/" @@ -599,6 +603,8 @@ ["/history" {:get history-endpoint :post history-endpoint}] + ["/info" {:get info-endpoint}] + ["/ledger/{*ledger-path}" #'ledger-specific-handler] ["/subscribe" diff --git a/src/fluree/server/handlers/ledger.clj b/src/fluree/server/handlers/ledger.clj index 5566a0a..35a720a 100644 --- a/src/fluree/server/handlers/ledger.clj +++ b/src/fluree/server/handlers/ledger.clj @@ -24,3 +24,8 @@ (if (and (map? result) (:status result) (:result result)) {:status (:status result), :body (:result result)} {:status 200, :body result}))) + +(defhandler info + [{:keys [fluree/conn fluree/opts] :as _req}] + (let [result (deref! (fluree/ledger-info conn (:ledger opts)))] + {:status 200 :body result})) diff --git a/test/fluree/server/integration/basic_query_test.clj b/test/fluree/server/integration/basic_query_test.clj index 017c7bd..f92fc46 100644 --- a/test/fluree/server/integration/basic_query_test.clj +++ b/test/fluree/server/integration/basic_query_test.clj @@ -3,7 +3,7 @@ [fluree.db.util.json :as json] [fluree.server.integration.test-system :as test-system - :refer [api-post create-rand-ledger json-headers run-test-server]])) + :refer [api-get api-post create-rand-ledger json-headers run-test-server]])) (use-fixtures :once run-test-server) @@ -301,6 +301,16 @@ "https://ns.flur.ee/ledger#retract" []}] (-> query-res :body (json/parse false)))))) + (testing "info" + (let [info-res (api-get :info {:headers {"fluree-ledger" ledger-name}})] + (is (= 200 (:status info-res))) + (is (= ["address" "alias" "branch" "commit" "index" "namespace-codes" "stats" "t"] + (-> info-res :body (json/parse false) keys sort)))) + (let [info-res (api-get (str "ledger/" ledger-name "/:info") {})] + (is (= 200 (:status info-res))) + (is (= ["address" "alias" "branch" "commit" "index" "namespace-codes" "stats" "t"] + (-> info-res :body (json/parse false) keys sort))))) + (testing "nonmatching routes are handled uniformly" (let [not-found1 (api-post "foo" {:body "{}" :headers json-headers}) not-found2 (api-post (str "ledger/" ledger-name "/:foo") {:body "{}" :headers json-headers})]