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 #-}
23 {-# LANGUAGE DataKinds #-}
24 {-# LANGUAGE DeriveGeneric #-}
25 {-# LANGUAGE FlexibleInstances #-}
26 {-# LANGUAGE TypeOperators #-}
27 {-# LANGUAGE TemplateHaskell #-}
28 {-# LANGUAGE OverloadedStrings #-}
33 import Gargantext.Prelude
36 import Network.Wai.Handler.Warp
39 import Servant.Mock (mock)
40 -- import Servant.API.Stream
42 import Data.Text (pack)
43 import Database.PostgreSQL.Simple (Connection, connect)
44 import System.IO (FilePath, print)
46 -- import Gargantext.API.Auth
47 import Gargantext.API.Node ( Roots , roots
51 import Gargantext.API.Count ( CountAPI, count, Query)
53 import Gargantext.Database.Utils (databaseParameters)
55 ---------------------------------------------------------------------
56 ---------------------------------------------------------------------
58 ---------------------------------------------------------------------
60 -- | startGargantext takes as parameters port number and Ini file.
61 startGargantext :: PortNumber -> FilePath -> IO ()
62 startGargantext port file = do
63 print ("Starting Gargantext server" <> show port)
64 print ("http://localhost:" <> show port)
65 param <- databaseParameters file
69 startGargantextMock :: PortNumber -> IO ()
70 startGargantextMock port = do
71 print (pack "Starting Mock server")
73 <> "-H \"content-type: application/json"
74 <> "-d \'{\"query_query\":\"query\"}\' "
75 <> "-v http://localhost:"
79 run port ( serve api $ mock api Proxy )
81 ---------------------------------------------------------------------
82 ---------------------------------------------------------------------
84 -- | Main routes of the API are typed
85 type API = "roots" :> Roots
87 :<|> "node" :> Capture "id" Int :> NodeAPI
88 :<|> "nodes" :> ReqBody '[JSON] [Int] :> NodesAPI
90 -- :<|> "counts" :> Stream GET NewLineFraming '[JSON] Count :> CountAPI
91 :<|> "count" :> ReqBody '[JSON] Query :> CountAPI
97 -- :<|> "list" :> Capture "id" Int :> NodeAPI
98 -- :<|> "ngrams" :> Capture "id" Int :> NodeAPI
99 -- :<|> "auth" :> Capture "id" Int :> NodeAPI
102 -- | Server declaration
103 server :: Connection -> Server API
104 server conn = roots conn
109 ---------------------------------------------------------------------
110 ---------------------------------------------------------------------
111 app :: Connection -> Application
112 app = serve api . server
116 ---------------------------------------------------------------------
117 ---------------------------------------------------------------------