It should be as simple as comparing the result of Network.Wai.requestMethod
against Network.Wai.methodPost
:
app request respond
| requestMethod request == methodPost
= respond $ case rawPathInfo request of
{- handle POST routes -}
| otherwise
= {- handle other request methods -}
Since there are constants for methodPost
, methodGet
, &c., you might as well use them, but Method
is an alias for ByteString
, so you could also use the OverloadedStrings
extension:
{-# LANGUAGE OverloadedStrings #-}
And then either compare with a string literal:
requestMethod request == "POST"
Or pattern match:
case requestMethod request of
"POST" -> {- … -}
"GET" -> {- … -}
…