haskell-servant / servant

Servant is a Haskell DSL for describing, serving, querying, mocking, documenting web applications and more!
https://docs.servant.dev/
1.83k stars 413 forks source link

Is there a stateful web application example like a blog service? #1152

Closed falsandtru closed 5 years ago

falsandtru commented 5 years ago

Probably beginners have to understand Context feature and a lot of undocumented details to create a stateful web application but this analysis is a hard work. Could you provide an implementation example?

phadej commented 5 years ago

E.g. https://haskell-servant.readthedocs.io/en/stable/cookbook/db-sqlite-simple/DBConnection.html recipe describes stateful application, the state is stored in SQLite, but in the same way you can store parts of it in IORefs or TVars.

falsandtru commented 5 years ago

That example doesn't support membership feature like CMS. I'm reading https://docs.servant.dev/en/stable/cookbook/jwt-and-basic-auth/JWTAndBasicAuth.html and https://docs.servant.dev/en/stable/cookbook/hoist-server-with-context/HoistServerWithContext.html but second page's examples lack authentication checks written in the first page. So I think I have to integrate the techniques written in the two pages to implement membership feature. I want that integrated example.

arianvp commented 5 years ago

I agree such a cookbook recipe like you describe would be useful.

falsandtru commented 5 years ago

Is there any site implemented by Servant provided for many users like Wordpress or EC site? I'm not sure that Servant can make it and supports it officially.

arianvp commented 5 years ago

I'm not sure i understand the question

Are you asking if servant is production ready? Yes it is, it is used by many Haskell companies and hosts quite a few big websites and APIs.

falsandtru commented 5 years ago

Can you list the achievements like the other products? In that list I want to find a web site which supports membership feature like Wordpress.

arianvp commented 5 years ago

Https://cachix.org is a good example as they're a non-trivial application with login support. Their API spec is here https://github.com/cachix/cachix/tree/master/cachix-api

We don't have a list of projects that use servant at the moment I think. I agree that such a list would be useful. If you're willing to make a PR to the website to create such a list of and projects that you encountered in your research that would be awesome.

falsandtru commented 5 years ago

An ability to provide both a personalized page and an not personalized page with the same URL is a required feature of WAF. Looks like that site lacks it. Is there another example which resolved it and uses cookie (generalized, not Basic or JWT) authentications?

falsandtru commented 5 years ago

That Servant code doesn't provide the front page as follows.

type CachixServantAPI = "api" :> "v1" :> ToServantApi CachixAPI

https://github.com/cachix/cachix/blob/master/cachix-api/src/Cachix/Api.hs#L162

alpmestan commented 5 years ago

Is there any site implemented by Servant provided for many users like Wordpress or EC site? I'm not sure that Servant can make it and supports it officially.

There are. I've written sites and apps that implement all sorts of things like this, all private projects though. We don't have a list like you're asking for at this point indeed, the closest would be to do a github code search like https://github.com/search?o=desc&q=%22import+Servant%22+language%3AHaskell&s=indexed&type=Code -- you can then try and see if there's something that fits in there, or to refine the search to find it.

More generally, Servant just provides a way to describe endpoints. What the handlers can do is identical with other frameworks, the question usually is more about how to """best""" achieve X or Y, how to design things.

falsandtru commented 5 years ago

I see, thanks.