1

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 1

1

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" ] 
Sign up to request clarification or add additional context in comments.

8 Comments

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 .
Hmm.. I think I forgot some brackets. Edited the answer.
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" }’ --
Here you include PUT and POST in the same list?
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" }
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.