Is jsonToRepJson broken?

I'm just starting to do Yesod + Haskell stuff. Is jsonToRepJson broken or something else?

I made this code below, but always get the error in the jsonToRepJson part. Doesn't it seem to get the expected type?

Any help would be great! Thanks: 3

{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} import Yesod import Data.Text data APP = APP instance Yesod APP mkYesod "APP" [parseRoutes| / TestR GET |] getTestR :: Handler RepJson getTestR = jsonToRepJson $ object ["test".= ("test"::Text)] main::IO() main = warpDebug 3001 APP 

this is what i get when i use runhaskell

 api.hs:18:12: Couldn't match expected type `RepJson' with actual type `Value' Expected type: Handler RepJson Actual type: HandlerT APP IO Value In the expression: jsonToRepJson $ object ["test" .= ("test" :: Text)] In an equation for `getTestR': getTestR = jsonToRepJson $ object ["test" .= ("test" :: Text)] 
+4
source share
2 answers

What I did, I used the TypeContent handler. If I understood correctly what I read, repSelect allows us to easily process what type of data presentation the client requests.

It reads the request header and checks if it requests JSON, then it spits out the JSON data, if it needs HTML, it will give an HTML page. Provided that you yourself have added the specific data needed with providRep .

Here is my code.

 mkYesod "APP" [parseRoutes| / TestR GET |] getTestR::Handler TypedContent getTestR = do selectRep $ do provideRep $ jsonToRepJson $ object $ (["test" .= ("test"::Text)]) main::IO() main = warpDebug 3001 APP 
0
source

You must convert your value toJSON .

For instance:.

 jsonToRepJson $ object [("result", toJSON resultValue)] 

:)

You can read about this change. Yesod 1.2

+7
source

Source: https://habr.com/ru/post/1484366/


All Articles