silkapp / rest

Packages for defining APIs, running them, generating client code and documentation.
http://silkapp.github.io/rest
390 stars 52 forks source link

The possibility to set custom success response codes #136

Open jonkri opened 9 years ago

jonkri commented 9 years ago

I would like to be able to return a custom response code upon success, such as setting 303 See Other instead of 200 OK.

Thanks for a nice library!

hesselink commented 9 years ago

That's a good idea. Do you have any idea how you would like the user API would look for this?

bergmark commented 9 years ago

How about having a customResponseCode that introduces a ToResponseCode constraint on the output dictionary?

hesselink commented 9 years ago

That sounds like a good idea, I'm not sure how it'd work out internally though. If it doesn't, another option would be to have a monadic setResponseCode inside the handlers. We'd have to change the type for the handlers, though, which is pretty nasty. If we ever do that (we've discussed it before) we should really make it opaque.

jonkri commented 9 years ago

setResponseCode seems like the nicest to work with. The return type of handlers should perhaps be more structured, i.e. data HandlerReturn = HandlerReturn { returnBody :: !ByteString, returnCode :: !Int, returnHeaders :: !(Map HeaderName HeaderValue)}.