yesod

How do I use wai-handler-devel with a simple wai application

不羁的心 提交于 2019-12-04 07:42:03
I have the basic "hello world" application setup using wai, and would like to use wai-handler-devel, but am unsure how to go about it and can't find any examples of it in usage on a wai project. {-# LANGUAGE OverloadedStrings #-} import Network.Wai import Network.HTTP.Types import Network.Wai.Handler.Warp (run) import Data.ByteString.Lazy.Char8 () -- Just for an orphan instance app :: Application app _ = return $ responseLBS status200 [("Content-Type", "text/plain")] "Hello, World!" main :: IO () main = do putStrLn $ "http://localhost:8080/" run 8080 app What do I need to do to get wai-handler

Return JSON from yesod handler

旧时模样 提交于 2019-12-04 03:45:33
I'm trying to write a simplest JSON response from Yesod's handler, but have some really stupid error (apparently). My handler code is this: -- HelloYesod/Handler/Echo.hs module Handler.Echo where import Data.Aeson (object, (.=)) import qualified Data.Aeson as J import Data.Text (pack) import Import import Yesod.Core.Json (returnJson) getEchoR :: String -> Handler RepJson getEchoR theText = do let json = object $ ["data" .= "val"] return json Error is this: Handler/Echo.hs:12:10: Couldn't match expected type `RepJson' with actual type `Value' In the first argument of `return', namely `json' In

Yesod, WebSockets and Persistent

冷暖自知 提交于 2019-12-04 03:43:24
I'm trying to implement a server for a turn based game in Haskell. My choice would be to use Yesod for adminstration and meta-information (like, what games a user participates in and such). I'd like to use web sockets to keep the in-game data overhead small. Looking at the ws-chat example, I'm not sure how to get access to the Handler Monad and with it Persistent. It would be perfect to have some bookkeeping-code for the connections wrapped around a "normal" Handler that itself updates the database and informs relevant users. This is how I think it should look like. {-# LANGUAGE QuasiQuotes,

Displaying dynamically generated images in Yesod

房东的猫 提交于 2019-12-04 02:59:21
I'm writing my first Yesod app. The application involves the user selecting to view a graph, dynamically generated based on data stored in a DB on the server. I know how to get the user request and create the image on the server's file system, but how do I create a response page presenting it? P.S. As I'm using GnuPlot to generate the image, I only know how to write it as a file to the file system, but If you happen to know how to get the data in memory it'll probably be even better. Thanks, hammar For a file on disk, you can use sendFile in your handler. getImageR = do -- ... save image data

Yesod: Using typesafe URLs in AJAX calls

家住魔仙堡 提交于 2019-12-04 02:57:56
In my Yesod project i have the following route: /api/hide/thread/#Text/#Int ApiHideThreadR GET I want to request it on the client side with javascript: function hideThreadCompletely(threadId, board) { $.getJSON("/api/hide/thread/"+board+"/"+threadId, function(data) { $('#thread-'+threadId).hide(); }); } But i can't use @{ApiHideTHreadR} because Yesod requires it's arguments on compile time. What is the proper solution for this, if i want API URLS to look like api/board/1/1 and not api/board?bid=1&tid=1 ? Keep using manually-defined URL's like "/api/hide/thread/"+board+"/"+threadId ? After some

Haskell Persistent: how get entity from db by key if i have key in integer variable?

时间秒杀一切 提交于 2019-12-04 02:17:03
I use Persistent orm with scotty web framework. I want to get value from db by id. These id are coming to me from GET request There are "get" function that takes "Key Entity" variable and returns "Maybe Entity". I use following code to get value from db k <- keyFromValues $ [(PersistInt64 myOwnIntVarFromRequest)] case k of Left _ -> {-some processing-} Right x -> do t <- liftIO . runDb $ get (x::Key Post) --Post is one of my models case t of Nothing -> {-processing-} Just x -> {-processing-} These code is extremly ugly. But i don't know how to do it better So my question is how obtain variable

MongoDB Example for Yesod / Persistent

孤街醉人 提交于 2019-12-04 02:10:24
Haskell and Yesod newbie here. I've been trying to follow the Integration with Yesod example from the Persistent chapter in the Yesod book (http://www.yesodweb.com/book/persistent). The Sqlite compiles and runs fine it seems. However, I'm trying to use MongDB and am having a hard time getting things to work. Specifically: In the example for sqlite: share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persist| The Yesod book says "Mongo code will use mongoSettings instead." But I can't find it in any of the modules, and the code doesn't compile. So instead, I had to use this instead of

use cabal2nix to create local nix environment for packages that aren't in nixpkgs

江枫思渺然 提交于 2019-12-03 19:58:49
I currently have a Yesod web application that I am developing on NixOS. I am using a default.nix file like described in O'Charles' blog post : { haskellPackages ? (import <nixpkgs> {}).haskellPackages }: haskellPackages.cabal.mkDerivation (self: { pname = "myblog"; version = "0.0.0"; src = ./.; isLibrary = true; isExecutable = true; buildDepends = with haskellPackages; [ aeson bson conduit dataDefault fastLogger hjsmin httpConduit monadControl monadLogger mongoDB persistent #persistentMongoDB persistentTemplate poolConduit shakespeare text waiExtra waiLogger warp yaml yesod yesodAuth yesodCore

Cabal install needs C library: Windows

我只是一个虾纸丫 提交于 2019-12-03 13:44:47
I am trying to cabal install yesod on my Windows machine. I have a relatively fresh install of the Haskell Platform. The cabal install failed, reporting that I need the sqlite3 C library in order to install "persistent", a package which Yesod relies upon. cabal: Missing dependency on a foreign library: * Missing C library: sqlite3 So I went to http://www.sqlite.org/download.html and grabbed both the C source and the precompiled binary. I tried using both, to no avail: cabal install persistent --extra-lib-dirs=C:\Path\To\C\Source\Files cabal install persistent --extra-lib-dirs=C:\Path\To\Binary

Store existing data-type with Yesod's Persistent

吃可爱长大的小学妹 提交于 2019-12-03 12:27:39
All the tutorials and references that I could find about Persistent describe in great detail how Persistent can automatically create a new data-type, schema, migration, etc. out of a single definition in its DSL. However, I couldn't find an explanation on how to get Persistent to handle already existing data-types. An example: Suppose I have an already existing Haskell module for some game logic. It includes a record type for a player. (It's meant to be used through lenses, hence the underscores.) data Player = Player { _name :: String , _points :: Int -- more fields ... } $(makeLenses '