]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API.hs
[FIX] fix offset in query.
[gargantext.git] / src / Gargantext / API.hs
1 {-|
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
8 Portability : POSIX
9
10 Main REST API of Gargantext (both Server and Client sides)
11
12 TODO/IDEA, use MOCK feature of Servant to generate fake data (for tests)
13 -}
14
15 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
16 {-# LANGUAGE DataKinds #-}
17 {-# LANGUAGE TemplateHaskell #-}
18 {-# LANGUAGE TypeOperators #-}
19
20 module Gargantext.API
21 where
22
23 import Gargantext.Prelude
24
25 import Network.Wai
26 import Network.Wai.Handler.Warp
27 import Servant
28 import Database.PostgreSQL.Simple (Connection, connect)
29 import System.IO (FilePath, print)
30
31
32 -- import Gargantext.API.Auth
33 import Gargantext.API.Node ( Roots , roots
34 , NodeAPI , nodeAPI
35 , NodesAPI , nodesAPI
36 )
37
38 import Gargantext.Database.Private (databaseParameters)
39
40
41
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
47 conn <- connect param
48 run port ( app conn )
49
50
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
55
56 -- :<|> "static"
57 -- :<|> "list" :> Capture "id" Int :> NodeAPI
58 -- :<|> "ngrams" :> Capture "id" Int :> NodeAPI
59 -- :<|> "auth" :> Capture "id" Int :> NodeAPI
60
61
62 -- | Server declaration
63 server :: Connection -> Server API
64 server conn = roots conn
65 :<|> nodeAPI conn
66 :<|> nodesAPI conn
67
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
77
78 api :: Proxy API
79 api = Proxy
80