Browse Source

Completing index page with all endpoints

Jim Barritt 11 months ago
parent
commit
324e0b4606
1 changed files with 19 additions and 1 deletions
  1. 19 1
      apps/petitions/decode-app/src/decode_app/handler.clj

+ 19 - 1
apps/petitions/decode-app/src/decode_app/handler.clj

@@ -42,8 +42,26 @@
42 42
       (catch Exception e
43 43
         {:status 500 :body "Internal Server Error"}))))
44 44
 
45
+(defn local-url
46
+  ([request] (local-url request ""))
47
+  ([request path] (let [{:keys [server-name server-port]} request]
48
+                    (format "http://%s:%s%s" server-name server-port path))))
49
+
50
+(defn api-index [request]
51
+  (array-map :api-name "decode-app"
52
+             :api-version "1.0"
53
+             :code-version "0.1"
54
+             :endpoints {:home {:url (local-url request "/") :description "Index page"}
55
+                         :status {:url (local-url request "/status") :description "Check for status of api and connections to services it depends on"}
56
+                         :petitions { :url (local-url request "/petitions") :description {:get "List of all petitions" :post "Create a new petition"}}
57
+                         :petition { :url (local-url request "/petitions/:id") :description "Retrieves a particular petition by id"}
58
+                         :close-petition {:url (local-url request "/close") :description {:post  "Close a petition (send id in body)"}}
59
+                         :sign-petition {:url (local-url request "/sign/petitions/:id") :description "Html form for signing a petition"}
60
+                         :login {:url (local-url request "/auth/in") :description "Html Login form"}
61
+                         :logout {:url (local-url request "/auth/out") :description "Logout action (Just invoke GET)"}}))
62
+
45 63
 (defroutes app-routes
46
-           (GET "/" [] (layout/application "Index" (contents/index)))
64
+           (GET "/" request [] (header (response (api-index request)) "Access-Control-Allow-Origin" "*"))
47 65
 
48 66
            (GET "/status" [] (header (response (status/get-status)) "Access-Control-Allow-Origin" "*"))
49 67