07: JSON Payloads
Update: 2018-08-25
Description
Returning actual Data in Json
Building out some hardcoded users
need to supply
User
before the datadon’t forget the
=
signWe 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 #-}
andimport 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
- JavaScript to Haskell
- Twitter: @jstoHaskell()
- Site: JSToHaskell
- microblog: @jtomchak
- Jesse Tomchak
- Twitter: @jtomchak
Comments
In Channel