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?
1 Answer
Well the ok :: (FilterMonad Response m) => a -> m a function is implemented as [src]:
ok :: (FilterMonad Response m) => a -> m a ok = resp 200
So it is the same way like you would write an ok response, except that you should use resp :: (FilterMonad Response m) => Int -> b -> m b with a custom return code.
For example:
resp 405 "Method not allowed" 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" ] 8 Comments
ib1
Thank you for your response , I am getting this error -- In the second argument of ‘resp’, namely ‘"Method not allowed"’ In a stmt of a 'do' block: resp 405 "Method not allowed" In the expression: do { method PUT; resp 405 "Method not allowed" } -- I tried to find what is wrong but no luck .
willeM_ Van Onsem
Hmm.. I think I forgot some brackets. Edited the answer.
ib1
I am getting the same error -- • No instance for (Data.String.IsString Response) arising from the literal ‘"Method not allowed"’ • In the second argument of ‘($)’, namely ‘"Method not allowed"’ In a stmt of a 'do' block: (resp 405) $ "Method not allowed" In the second argument of ‘($)’, namely ‘do { method [PUT, POST]; (resp 405) $ "Method not allowed" }’ --
willeM_ Van Onsem
Here you include
PUT and POST in the same list?ib1
Yeah sorry wrong copy this is the one -- No instance for (Data.String.IsString Response) arising from the literal ‘"Method not allowed"’ • In the second argument of ‘($)’, namely ‘"Method not allowed"’ In a stmt of a 'do' block: (resp 405) $ "Method not allowed" In the expression: do { method PUT; (resp 405) $ "Method not allowed" }
|