I have been trying to create a custom happstack response the 405 "Method not allowed" so if someone calls the API with a POST or PUT method they will get this response. I am new to happstack. Any ideas how I can do that?
So we can for example block PUT and POST requests with something like:
main :: IO ()
main = simpleHTTP nullConf $ msum
[ do method GET
ok $ "This is allowed.\n"
, do method PUT
(resp 405) $ "Method not allowed"
, do method POST
(resp 405) $ "Method not allowed"
]
Well the
ok :: (FilterMonad Response m) => a -> m afunction is implemented as [src]:So it is the same way like you would write an
okresponse, except that you should useresp :: (FilterMonad Response m) => Int -> b -> m bwith a custom return code.For example:
So we can for example block
PUTandPOSTrequests with something like: