07: JSON Payloads

07: JSON Payloads

Update: 2018-08-25
Share

Description

Returning actual Data in Json




  • Building out some hardcoded users



  • need to supply User before the data



  • don’t forget the = sign



  • We could manually build the encode and decode to/from JSON, but Generics, lets you automatically do things based on the data type




    • adding {-# LANGUAGE DeriveGeneric #-} and import GHC.Generics



    • don’t forget to add instance



    • instance ToJSON User
      instance FromJSON User




Now we are able to see the output of having the generic encoder



Ok, two modules loaded.
*Main Lib> import Data.Aeson (encode)
*Main Lib Data.Aeson> encode bob
"{\"userName\":\"Bobby Boy\",\"userId\":1}"



  • And now with that it looks like Scotty has a function json for use to return a json payload. sweet



    get "/users" $ do
json allUsers


Resources





Follow





Comments 
In Channel
08: Docker

08: Docker

2018-09-06--:--

07: JSON Payloads

07: JSON Payloads

2018-08-25--:--

06: Routed Params

06: Routed Params

2018-08-23--:--

05: Routes In Haskell

05: Routes In Haskell

2018-08-16--:--

04: Practical Haskell

04: Practical Haskell

2018-08-15--:--

03: Lists

03: Lists

2018-08-09--:--

02:  Tooling

02: Tooling

2018-08-08--:--

00: Pilot

00: Pilot

2018-08-01--:--

00:00
00:00
x

0.5x

0.8x

1.0x

1.25x

1.5x

2.0x

3.0x

Sleep Timer

Off

End of Episode

5 Minutes

10 Minutes

15 Minutes

30 Minutes

45 Minutes

60 Minutes

120 Minutes

07: JSON Payloads

07: JSON Payloads