From efd1d8cdcd1441ce4f187a832641f530809abf89 Mon Sep 17 00:00:00 2001 From: "Thomas R. Koll" Date: Tue, 19 Jan 2016 09:15:59 +0100 Subject: [PATCH] api: stuff all the endpoints under /api/v1/ --- hledger-api/hledger-api.hs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/hledger-api/hledger-api.hs b/hledger-api/hledger-api.hs index e2f4d79ec..6aaa52920 100644 --- a/hledger-api/hledger-api.hs +++ b/hledger-api/hledger-api.hs @@ -82,21 +82,25 @@ type HledgerApi = :<|> "accounts" :> Get '[JSON] [Account] :<|> "accounts" :> Capture "acct" AccountName :> Get '[JSON] AccountTransactionsReport +type CombinedServer = + "api" :> + "v1" :> HledgerApi + :<|> Raw + hledgerApiApp :: Journal -> Wai.Application -hledgerApiApp j = Servant.serve api server +hledgerApiApp j = Servant.serve api combinedServer where - api :: Proxy HledgerApi + api :: Proxy CombinedServer api = Proxy - server :: Server HledgerApi - server = + apiServer :: Server HledgerApi + apiServer = accountnamesH :<|> transactionsH :<|> pricesH :<|> commoditiesH :<|> accountsH :<|> accounttransactionsH - :<|> serveDirectory "static" where accountnamesH = return $ journalAccountNames j transactionsH = return $ jtxns j @@ -114,6 +118,10 @@ hledgerApiApp j = Servant.serve api server thisacctq = Acct $ accountNameToAccountRegex a -- includes subs return $ accountTransactionsReport ropts j q thisacctq + combinedServer :: Server CombinedServer + combinedServer = apiServer + :<|> serveDirectory "static" + -- brief toJSON definitions included to avoid https://github.com/bos/aeson/issues/290 -- use toEncoding = genericToEncoding defaultOptions instead ? instance ToJSON ClearedStatus where toJSON = genericToJSON defaultOptions