scotty

Add print in Scotty do block

心已入冬 提交于 2021-02-10 18:10:31
问题 I'm very new to Haskell so sorry in advance if the question is silly, but I was not able to find the solution in google. Let's say that I have this program using the Scotty web framework: responseUserByName :: ActionM () responseUserByName = do name <- param "name" user <- liftAndCatchIO $ getUserByUserName name json user I would like to add a log since it is failing at runtime and I cannot tell why. So my idea was to add some print in the do block to check values. But since the do block has

Scotty monad transformer for per-handler Reader

ⅰ亾dé卋堺 提交于 2020-02-21 12:44:07
问题 In the question Web, Scotty: connection pool as monad reader it is shown how to use ScottyT to embed a Reader monad in the stack to access a static configuration (in that case, a connection pool). I have a similar question, but simpler – or at least I thought so… I want to add a Reader to a single handler (i.e. a ActionT ), not the whole app. I started modifying the program from the question above, but I cannot figure out how to turn an ActionT Text (ReaderT String IO) into the ActionT Text

Haskell Scotty and Angularjs: jsonData function stopped parsing json data sent with $http.post()

安稳与你 提交于 2019-12-24 11:10:47
问题 I have a Haskell/Scotty app with Angularjs as frontend. It worked flawlessly with regards to JSON parsing. Then it suddenly stopped for no reason. It happend after some Scotty and its dependencies version bump. There is not much error feed back from the scotty jsonData function which parses JSON body. None of the POST requests from Angular work at the moment. I can't figure out what happened. I don't know which code example would be useful as any JSON POSTs result with jsonData - no parse

How do I add the Reader monad to Scotty's monad?

人盡茶涼 提交于 2019-12-22 05:40:10
问题 I'm trying to use Scotty to build a very simple API. I'd like to extend the Scotty monads such that my route handler actions are able to access an unchanging environment. I believe the way to do this would be to add a Reader monad to the stack. For now I just want to pass some Text data around. I've extended the Scotty monads as follows: type BrandyScottyM = ScottyT TL.Text (ReaderT T.Text IO) type BrandyActionM = ActionT TL.Text (ReaderT T.Text IO) https://github.com/stu-smith/Brandy/blob

Use StateT within Web.Scotty

ε祈祈猫儿з 提交于 2019-12-21 04:27:17
问题 I'm trying to make a silly webserver that stores data as State . I'm using Web.Scotty. I've used ReaderT before with scotty to access config, but following the same approach doesn't work here. It resets the state on every request. I want to set the initial state when the program starts, then have that same state stick around for the whole life of the program. How can I make this work? (The following creates a new state every request) {-# LANGUAGE OverloadedStrings #-} import Web.Scotty.Trans

Using ReaderT transformer in ScottyT (vs ActionT)

孤街浪徒 提交于 2019-12-11 07:35:42
问题 I'm trying to thread configuration through my Scotty based application using ReaderT monad transformer approach, and having trouble doing so. I have to use configuration both when defining routes (as some of them depend on the config) and when handling actual requests. The latter works just fine in the ActionT, but no matter what I try I just can't get the types right in ScottyT. Here's the minimal example I compiled from the ReaderT sample from Scotty GitHub repository: {-# LANGUAGE

Scotty Using MongoDB

心不动则不痛 提交于 2019-12-07 09:56:35
问题 I'm relatively new to Haskell, and this is my first time working with monad transformers. I'd really appreciate some help. runQuery :: Pipe -> Query -> ActionM (Either Failure [Document]) runQuery pipe query = access pipe master "nutrition" (find query >>= rest) main = do pipe <- runIOE $ connect $ host "127.0.0.1" scotty 3000 $ do post "/" $ do b <- body let user :: Either String User = eitherDecode b case user of Left err -> text . pack $ "Could not decode the user:" ++ err ++ ":\n" ++

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

狂风中的少年 提交于 2019-12-05 17:31:55
问题 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-}

Scotty Using MongoDB

随声附和 提交于 2019-12-05 15:25:10
I'm relatively new to Haskell, and this is my first time working with monad transformers. I'd really appreciate some help. runQuery :: Pipe -> Query -> ActionM (Either Failure [Document]) runQuery pipe query = access pipe master "nutrition" (find query >>= rest) main = do pipe <- runIOE $ connect $ host "127.0.0.1" scotty 3000 $ do post "/" $ do b <- body let user :: Either String User = eitherDecode b case user of Left err -> text . pack $ "Could not decode the user:" ++ err ++ ":\n" ++ (show b) Right u -> do let query::Query = (select ["i_name" =: ["$in" =: map (unpack . name) (foods u)]]

How do I add the Reader monad to Scotty's monad?

强颜欢笑 提交于 2019-12-05 08:12:55
I'm trying to use Scotty to build a very simple API. I'd like to extend the Scotty monads such that my route handler actions are able to access an unchanging environment. I believe the way to do this would be to add a Reader monad to the stack. For now I just want to pass some Text data around. I've extended the Scotty monads as follows: type BrandyScottyM = ScottyT TL.Text (ReaderT T.Text IO) type BrandyActionM = ActionT TL.Text (ReaderT T.Text IO) https://github.com/stu-smith/Brandy/blob/0838a63537d7e396ac82d58d460c6529349303d3/src/Core.hs So my first question is, is this the correct