-
Notifications
You must be signed in to change notification settings - Fork 4
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
3 changed files
with
33 additions
and
26 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
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
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,28 +1,25 @@ | ||
{-| Most basic Hello world server. | ||
It has only one route which outputs the greeting to the user | ||
-} | ||
module Main ( | ||
main, | ||
) where | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
import Mig | ||
-- \| Most basic Hello world server. | ||
-- It has only two routes which output the text as JSON to the user | ||
import Mig.Json.IO | ||
|
||
{-| We can render the server and run it on port 8085. | ||
It uses wai and warp. | ||
-} | ||
-- | Starts server on port 8085. | ||
main :: IO () | ||
main = do | ||
putStrLn ("The hello world server listens on port: " <> show port) | ||
runServer port server | ||
where | ||
port = 8085 | ||
main = runServer 8085 (withSwagger def server) | ||
|
||
{-| Init simple hello world server which | ||
replies on a single route | ||
-} | ||
-- | The server definition with two routes | ||
server :: Server IO | ||
server = "api/v1/hello" /. hello | ||
server = | ||
"api/v1" | ||
/. [ "hello" /. hello | ||
, "bye" /. bye | ||
] | ||
|
||
-- | Handler takes no inputs and marked as Get HTTP-request that returns Text response as Json. | ||
hello :: Get IO (Resp Json Text) | ||
hello = pure $ ok "Hello World!" | ||
-- | The handler definition as a function | ||
hello :: Get (Resp Text) | ||
hello = pure $ ok "Hello World" | ||
|
||
-- | The handler definition as a function with a query parameter to ask for the user name | ||
bye :: Query "user" Text -> Get (Resp Text) | ||
bye (Query name) = pure $ ok ("Goodbye " <> name) |