Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Servant IP Address Sample
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
import Control.Monad.IO.Class -- liftIO
import Network.Wai.Handler.Warp
import Network.Socket
import Servant
type MyAPI = "ip" :> RemoteHost :>Get '[JSON] [String]
myInfo :: SockAddr -> Handler [String]
myInfo addr = do
liftIO $ print addr
return [show addr]
myServer :: Server MyAPI
myServer = myInfo
myProxy :: Proxy MyAPI
myProxy = Proxy
myApp :: Application
myApp = serve myProxy myServer
main :: IO ()
main = run 8081 myApp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment