2 Module : Gargantext.API
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 App type, the main monad in which the bot code is written with.
13 Provide config, state, logs and IO
14 type App m a = ( MonadState AppState m
16 , MonadLog (WithSeverity Doc) m
18 Thanks @yannEsposito for this.
21 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
22 {-# LANGUAGE DataKinds #-}
23 {-# LANGUAGE TemplateHaskell #-}
24 {-# LANGUAGE TypeOperators #-}
25 {-# LANGUAGE DeriveGeneric #-}
30 import Gargantext.Prelude
33 import Network.Wai.Handler.Warp
36 import Servant.Mock (mock)
37 -- import Servant.API.Stream
39 import Data.Text (pack)
40 import Database.PostgreSQL.Simple (Connection, connect)
41 import System.IO (FilePath, print)
43 -- import Gargantext.API.Auth
44 import Gargantext.API.Node ( Roots , roots
48 import Gargantext.API.Count ( CountAPI, count, Query)
50 import Gargantext.Database.Utils (databaseParameters)
52 ---------------------------------------------------------------------
53 ---------------------------------------------------------------------
55 ---------------------------------------------------------------------
57 -- | startGargantext takes as parameters port number and Ini file.
58 startGargantext :: PortNumber -> FilePath -> IO ()
59 startGargantext port file = do
60 print ("Starting Gargantext server" <> show port)
61 print ("http://localhost:" <> show port)
62 param <- databaseParameters file
66 startGargantextMock :: PortNumber -> IO ()
67 startGargantextMock port = do
68 print (pack "Starting Mock server")
70 <> "-H \"content-type: application/json"
71 <> "-d \'{\"query_query\":\"query\"}\' "
72 <> "-v http://localhost:"
76 run port ( serve apiMock $ mock apiMock Proxy )
78 ---------------------------------------------------------------------
79 ---------------------------------------------------------------------
81 -- | Main routes of the API are typed
82 type API = "roots" :> Roots
84 :<|> "node" :> Capture "id" Int :> NodeAPI
85 :<|> "nodes" :> ReqBody '[JSON] [Int] :> NodesAPI
88 -- :<|> "counts" :> Stream GET NewLineFraming '[JSON] Count :> CountAPI
89 type APIMock = "count" :> ReqBody '[JSON] Query :> CountAPI
95 -- :<|> "list" :> Capture "id" Int :> NodeAPI
96 -- :<|> "ngrams" :> Capture "id" Int :> NodeAPI
97 -- :<|> "auth" :> Capture "id" Int :> NodeAPI
100 -- | Server declaration
101 server :: Connection -> Server API
102 server conn = roots conn
107 ---------------------------------------------------------------------
108 ---------------------------------------------------------------------
109 app :: Connection -> Application
110 app = serve api . server
115 apiMock :: Proxy APIMock