Created
November 23, 2017 13:42
-
-
Save knaman2609/23eae6d40ea414121dacc73fe858e9c2 to your computer and use it in GitHub Desktop.
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
import Control.Monad.Except.Trans | |
import Data.HTTP.Method | |
import Network.HTTP.Affjax | |
import Network.HTTP.ResponseHeader | |
import Network.HTTP.StatusCode | |
import Prelude | |
import Control.Plus | |
import Control.Monad.Aff.Console (log) | |
import Control.Monad.Eff.Class (liftEff) | |
import Data.Either (Either(..)) | |
import Data.Argonaut.Core | |
type Resp = { | |
status :: StatusCode, | |
headers :: Array ResponseHeader, | |
response :: Json | |
} | |
fn1 :: forall eff. Aff (ajax :: AJAX | eff) Resp | |
fn1 = affjax $ defaultRequest { url = "https://api.github.com/users/octocat", method = Left GET } | |
fn2 :: forall eff. Aff (ajax :: AJAX | eff) Resp | |
fn2 = affjax $ defaultRequest { url = "https://api.github.com/users/", method = Left GET } | |
ffn1 = ExceptT $ do | |
res <- fn1 | |
case res.status of | |
StatusCode 200 -> pure $ (Right "Hello") | |
StatusCode _ -> pure $ (Left "InCorrect") | |
ffn2 = ExceptT $ do | |
res <- fn2 | |
case res.status of | |
StatusCode 200 -> pure $ (Right "Correct") | |
StatusCode _ -> pure $ (Left "InCorrect") | |
main = launchAff $ do | |
x <- runExceptT $ ffn1 <|> ffn2 | |
case x of | |
Left err -> log err | |
Right res -> log res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment