sqliteresthaskellysod

Introductory example on serving data from sqlite database via REST API with the yesod web frame work in haskell


I want a "keep it simple and stupid" (i.e., "make it as simple as possible but not simpler") way of serving data that is stored in a sqlite data base. In haskell I want to use the ysod web framework. Actually, as I am only severing data, I need to implement simply GET requests.

I am not interested in generating html, css, javascript, session management, user management, web blog applications, authentication, etc.

The last two hours I read several webpages from the Ysod Book and tutorials on fpcomplete. Up til now I could not get an example running.

Finally I tried to get an example from a blog post running . Although the example is not too old and from 2013, yesod changed a lot since then and it is not obvious on how to get the example running.

I adapted the following lines in the blog post example. Missing language extensions:

{-# LANGUAGE ViewPatterns               #-}
{-# LANGUAGE ScopedTypeVariables        #-}

Further persist is no longer available, thus persistLowerCase:

share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
Stuff
    value Text
    ValueName value value
    deriving Show
|]

Still, there are probably a bunch of fixes needed to get the example running.

So prior to investing more time my question is: where do I find a up to date example or tutorial on how to use ysod with sqlite to program a REST API serving JSON data?


Solution

  • How about the Yesod book's Persistent chapter?