0 | module TyTTP.HTTP.Producer.JSON
 1 |
 2 | import Data.Buffer.Ext
 3 | import TyTTP
 4 | import TyTTP.HTTP
 5 | import JSON
 6 |
 7 | export
 8 | sendJSON :
 9 |   Applicative m
10 |   => ToJSON j
11 |   => j
12 |   -> Context me u v h1 s StringHeaders a b
13 |   -> m $ Context me u v h1 s StringHeaders a (Publisher IO e Buffer)
14 | sendJSON j ctx = do
15 |   let bodyJson = encode j
16 |   let stream : Publisher IO e Buffer = Stream.singleton $ fromString $ bodyJson
17 |   pure $ { response.body := stream
18 |          , response.headers :=
19 |            [ ("Content-Type", "application/json")
20 |            , ("Content-Length", show $ length bodyJson)
21 |            ]
22 |          } ctx
23 |