2 Module : Gargantext.Server
3 Description : Server API
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Main REST API of Gargantext (both Server and Client sides)
12 TODO/IDEA, use MOCK feature of Servant to generate fake data (for tests)
15 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
16 {-# LANGUAGE DataKinds #-}
17 {-# LANGUAGE TemplateHaskell #-}
18 {-# LANGUAGE TypeOperators #-}
23 import Gargantext.Prelude
26 import Network.Wai.Handler.Warp
28 import Database.PostgreSQL.Simple (Connection, connect)
29 import System.IO (FilePath, print)
32 -- import Gargantext.API.Auth
33 import Gargantext.API.Node ( Roots , roots
38 import Gargantext.Database.Private (databaseParameters)
42 -- | startGargantext takes as parameters port number and Ini file.
43 startGargantext :: Int -> FilePath -> IO ()
44 startGargantext port file = do
45 print ("Starting server on port " <> show port)
46 param <- databaseParameters file
51 -- | Main routes of the API are typed
52 type API = "roots" :> Roots
53 :<|> "node" :> Capture "id" Int :> NodeAPI
54 :<|> "nodes" :> ReqBody '[JSON] [Int] :> NodesAPI
57 -- :<|> "list" :> Capture "id" Int :> NodeAPI
58 -- :<|> "ngrams" :> Capture "id" Int :> NodeAPI
59 -- :<|> "auth" :> Capture "id" Int :> NodeAPI
62 -- | Server declaration
63 server :: Connection -> Server API
64 server conn = roots conn
68 -- | TODO App type, the main monad in which the bot code is written with.
69 -- Provide config, state, logs and IO
70 -- type App m a = ( MonadState AppState m
71 -- , MonadReader Conf m
72 -- , MonadLog (WithSeverity Doc) m
73 -- , MonadIO m) => m a
74 -- Thanks @yannEsposito for this.
75 app :: Connection -> Application
76 app = serve api . server