The features of this web framework:
Type safe routes, specify url-handler mapping in one place. For example, we want a url mapping for blog as "/blog/year-month-day" to Handler Int Int Int, where year, month and day are integers. We can declare as follows:
data Blog = Blog Int Int Int deriving (Show, Eq, Typeable)rBlog = blog <$> text "/blog/" *> int <-> int <-> int
$(defineIsomorphisms ''Blog)
instance Handler Blog where
get b@(Blog y m d) _ = do
t <- liftIO getClockTime
return $ responseHtml $ trans' "blog" ++ show b ++ show t
We can reverse this mapping from handler value automatically, thus don't need to construct url string manually in code, avoiding url errors.
ghci>url (Blog 2011 9 19) == "/blog/2011-9-19"
Simple yet elegant handler via type class.
class Handler a where
get, post, put, delete, handle :: a -> Application
handle a req = case requestMethod req of
m | m == methodGet -> get a req
| m == methodPost -> post a req
| m == methodPut -> put a req
| m == methodDelete -> delete a req
otherwise -> unimplemented req
Flexible template system, utilize exsisting libraries such as Blaze-Html and Hastache.
Easy i18n
Port from snap-auth.
Improving the DSH library is my current preference.
For the example code listed above, please refer to https://github.com/lilac/ivy-example/