I want to write API endpoint that would return different http code depending on incoming parameter and state of external world. In python, it would look like following (wsgi):
def application(environ, start_response):
if check_foo():
start_response("200 OK", [])
return b'42'
else:
start_response("201 Created", [])
return b'43'
It is not oblivious how to do it with Servant:
type UserAPI = Verb 'GET 201 '[JSON] Int :<|> Verb 'GET 200 '[JSON] Int
server :: Server UserAPI
server = pure 42 :<|> pure 43
compiles and works, but only returns 42, http code 201. Sure, I can sneak anything I want with ServerError, but this way I lose all advantages of servant, and will have to do serialization myself.
Alternatively, I could push distinction between 200 and 201 into return data, but it is important to me to keep http codes informative.
So, is there way for one endpoint to return different two different http code, with both of them considered "success"?