-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module LiBro.WebService where | ||
|
||
import LiBro.Config | ||
import LiBro.Control | ||
import Control.Concurrent | ||
import LiBro.Data (LiBroData) | ||
|
||
data LiBroState = LiBroState | ||
{ config :: Config | ||
, mvBlocking :: MVar Blocking | ||
, mvData :: MVar LiBroData | ||
} | ||
|
||
lsConfig :: LiBroState -> IO Config | ||
lsConfig = return . config | ||
|
||
lsData :: LiBroState -> IO LiBroData | ||
lsData = readMVar . mvData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
module LiBro.WebService.API where | ||
|
||
import LiBro.WebService.Types | ||
import Data.Proxy | ||
import Servant.API | ||
|
||
type LiBroAPI = "hello" :> Get '[PlainText] String | ||
type LiBroAPI = "hello" :> Get '[JSON] PersonIDs | ||
:<|> "yay" :> Get '[PlainText] String | ||
|
||
libroApi :: Proxy LiBroAPI | ||
libroApi = Proxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
module LiBro.WebService.Server where | ||
|
||
import LiBro.WebService.API | ||
import LiBro.WebService.Types | ||
import Servant | ||
|
||
server :: Server LiBroAPI | ||
server = return "Hello LiBro!" | ||
handleHello :: Handler PersonIDs | ||
handleHello = return $ PersonIDs [17, 42] | ||
|
||
handleYay :: Handler String | ||
handleYay = return "Yay!" | ||
|
||
libro :: Application | ||
libro = serve libroApi server | ||
libro = serve libroApi | ||
$ handleHello | ||
:<|> handleYay |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module LiBro.WebService.Types where | ||
|
||
import Data.Aeson | ||
import GHC.Generics | ||
|
||
newtype PersonIDs = PersonIDs {personIDs :: [Int]} deriving Generic | ||
instance ToJSON PersonIDs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters