servant 0.4 released

Since the last major release, a lot happened in and around servant. Definitely enough to justify a new release. This post announces new releases of all the servant packages, with many local changes but also some major ones that affect all packages. You can find the detailed changelogs at the end of this post, but here are a few major features you may want to learn about. This website also features a new tutorial that explains how to use servant from scratch.

Response headers There was no easy way so far to have handlers add headers to a response. We’ve since come up with a solution that stays true to the servant spirit: what headers your response will include (and what their types are) is still enforced statically: type MyHandler = Get '[ JSON ] ( Headers '[ Header "Location" Link ] User ) myHandler :: Server MyHandler myHandler = return $ addHeader < someLink > $ < someuser > servant-docs and servant-client are also response-header aware. Our current solution isn’t something we are entirely happy with from an internal persepctive. We use overlapping instances for all the handlers, which some might think is already a problem. But more concretely, there’s the threat of an exponential blowup in the number of instances we have to declare. And that can be a problem for end users too, if they decide to further modify behavior via a similar mechanism. But these things thankfully don’t seem to pose any immediate problems.

mkLink Somewhere between the 0.2 release and now, mkLink got a whole lot better (thanks Christian Marie!). mkLink makes urls that are statically guaranteed to belong to your API, without any Template Haskell. Combined with response headers, you can now easily create, for instance, type-safe redirect headers. Combined with the new HTML support, you can easily make links that you know will not 404.

Left We also changed the default type of handlers from EitherT (Int,String) IO a to EitherT ServantErr IO a . Now it is possible to return headers and a response body in the Left case. We also now export function errXXX (where XXX is a 300-599 HTTP status code) with sensible reason strings.

BaseUrl We also changed the client function from servant-client so that, instead of returning various functions that each take a BaseUrl argument (often in inconvenient argument positions), the client function itself takes a BaseUrl argument, and the functions it returns don’t. So the type of client went from client :: HasClient ( Canonicalize layout) => Proxy layout -> Client layout To client :: HasClient ( Canonicalize layout) => Proxy layout -> BaseUrl -> Client layout

Website We also decided to switch to hakyll in order to be able to have a blog as well as some static pages that collect tips and tricks that people have found. We also used this opportunity to rewrite the getting started into a more informative tutorial, now available here.

Posted on May 10, 2015 by The servant team