from Hacker News

Okapi – A micro web framework for Haskell

by njrc9 on 11/18/22, 1:23 PM with 27 comments

  • by rstarast on 11/19/22, 9:05 AM

    The way this does routing leads to quite hard to read code, compare https://www.okapi.wiki/docs/todo-app:

        todoAPI conn = getTodo conn <|> getAllTodos conn
    
    with

        getTodo conn = do
          methodGET
          pathParam @Text `is` "todos"
          todoID <- pathParam @Int
          ...
    
    so you need to keep in mind both the order of the alternatives in todoAPI as well as the bodies of the individual handlers. That gets unwieldy very quickly.

    It also seems likely to lead to the same problems with error handling that you tend to get with combinator parsers, where you usually only get details about the last failing branch, while the interesting failure might have been an earlier one.

    Quiz question (I don't know the answer): What happens to a request for /todos/foo?

  • by mark_l_watson on 11/19/22, 3:55 PM

    Looks really nice but I haven’t tried it yet. I wrote a small book on my take on Haskell programming using a small subset of the language (read for free on my web site https://markwatson.com). When I update my book I might add an Okapi example. I have played around with Spock for simple web apps and that is nice enough, but I am really impressed by the care in putting together the Okapi documentation web site. Great material, nicely presented.
  • by njrc9 on 11/19/22, 7:15 AM

    The author of this framework is also doing very interesting work on building Haskell server pages [1], taking inspiration from redbean's Lua server pages[2].

    [1] https://monadic.systems/post7 [2] https://redbean.dev/#lua

  • by __derek__ on 11/19/22, 12:28 AM

    In case anyone else who's played with search engines thinks, "Wait, Okapi sounds familiar," here you go: https://en.wikipedia.org/wiki/Okapi_BM25

    The "Get Started" and "View on GitHub" links both have `href="/"`, so they don't work.

  • by jbirer on 11/18/22, 11:29 PM

    Thanks, this made me realize how good Haskell is for declaring API routing.
  • by revskill on 11/19/22, 6:51 AM

    Hope the docs for Monad Transformer could be completed for me to understand and use the framework then.
  • by badrabbit on 11/18/22, 9:22 PM

    Haskell for web? That's very impressive if you can get it to work at scale. This is the hardest language I have ever personally tried to learn.