top | item 33654192

Okapi – A micro web framework for Haskell

83 points| njrc9 | 3 years ago |okapi.wiki

27 comments

order

rstarast|3 years ago

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?

mark_l_watson|3 years ago

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.

__derek__|3 years ago

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.

vector_spaces|3 years ago

Thanks for sharing, although I feel like this is more likely just following the "put a bird on it" trend of naming software frameworks after animals

jbirer|3 years ago

Thanks, this made me realize how good Haskell is for declaring API routing.

revskill|3 years ago

Hope the docs for Monad Transformer could be completed for me to understand and use the framework then.

badrabbit|3 years ago

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.

kccqzy|3 years ago

Of course you can. As early as 2012, Michael Snoyman has written a book about it, Developing Web Applications with Haskell and Yesod. Yesod is an old web framework by now, but it's not even the oldest. Happstack is even older than that.

MarkMarine|3 years ago

Have you tried C? I’m not being snarky, remembering all the undefined behavior is a task in itself. I’m a Haskell neophyte, but I often find myself reaching for things haskell has in the box when I’m writing something in another language.

To me, it’s like the people who describe a cat as “just like a dog” as a positive trait for the cat. Why deal with the “just like” version if you can have the real thing? Just get a dog. So I find myself reaching for these tools and then I try to just go to the real thing. Unfortunately I can’t run Haskell on an ESP32 :)

Btw, this is not to denigrate cats, they are great in their own right. Not for me, I’m violently allergic and somewhat particular to having the things I ensure exist be thankful, but I respect everyone’s choices in the fluffy friend department.

kobalsky|3 years ago

monads still keep me awake at night