Last active
August 29, 2015 14:00
-
-
Save kgadek/11380592 to your computer and use it in GitHub Desktop.
AGH Informatyka (sem 10) :: Zaawansowane Techniki Integracji Systemów :: Laboratoria 1
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
{-# LANGUAGE OverloadedStrings, DeriveGeneric #-} | |
import Web.Scotty | |
import Data.Aeson | |
import GHC.Generics | |
data Stuff = Stuff { dt :: Things | |
} deriving (Show, Generic) | |
instance FromJSON Stuff | |
instance ToJSON Stuff | |
data Things = Things { id :: Int | |
, tp :: String | |
, msg :: String | |
} deriving (Show, Generic) | |
instance FromJSON Things | |
instance ToJSON Things | |
main :: IO () | |
main = scotty 3000 $ do | |
post "/" $ do | |
bd <- body | |
case decode bd of | |
Nothing -> html "LOL NOPE! <strong>objection!</strong>" | |
Just (Stuff things) -> raw $ encode (Stuff things { tp = "response" }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dla porównania — analogiczny program w Pythonie.
Ciężko pokonać bottle.py pod względem rozmiaru kodu w tym przykładzie, niemniej na usprawiedliwienie Haskella: dodatkowo weryfikuje protokół wejściowy i wyjściowy!