digitallyinduced / ihp

🔥 The fastest way to build type safe web apps. IHP is a new batteries-included web framework optimized for longterm productivity and programmer happiness
https://ihp.digitallyinduced.com/
MIT License
4.95k stars 197 forks source link

Support to send json data via web socket #1181

Closed rvarun11 closed 3 years ago

rvarun11 commented 3 years ago

Right now, the web socket controller only supports sendTextData to send data via the web socket controller and sending data via json only seems to be possible by using Text and then parsing the JSON in the frontend as follows:

.
.
.
let jsonMsg = "\"message\": \""<> msg <> "\""
let jsonCreatedAt = "\"createdAt\": \""<> (show $ get #createdAt chatMsg) <> "\""

sendTextData ("{" <> jsonMsg <> "," <> jsonCreatedAt <> "}") 

This becomes very tedious especially if you more complex data and should be supported natively by IHP.

mpscholten commented 3 years ago

Agree, the DataSync API e.g. also added a helper called sendJSON https://github.com/digitallyinduced/ihp/blob/master/IHP/DataSync/Controller.hs#L46 as a workaround for now you could import that function from IHP.DataSync.Controller

rvarun11 commented 3 years ago

Thank you. That's better than using sendTextData.

Should I keep this issue open?

mpscholten commented 3 years ago

yes 👍

mpscholten commented 3 years ago

The function is now exposed :) You can find docs here https://github.com/digitallyinduced/ihp/commit/4d93293b6cf9418373e4a01ae86485db14ed073a