Json input map but not output in Suave
Suave.Json.mapJson
maps the input JSON to an object in your function, then maps the output of your function to JSON.
The problem is that I am happy with how it maps to my function, but I need to return a json string response and not have my output serialized to JSON for me. How can i do this?
I am currently getting my output serialized twice. My code:
let executeQuery : Query -> string = //Query is my deserialised json input, the return value is a json string
let app = POST >=> path "/graphql" >=> Json.mapJson executeQuery >=> setMimeType "application/json; charset=utf-8"
startWebServer defaultConfig app
source to share
If you look at the source code for Suave , you can see what mapJson
is shorthand for mapJsonWith fromJson toJson
. Functions fromJson
and toJson
are the default JSON deserializer and serializer (respectively), but you can create your own instead - or just use id
to say "draw this direction without changing it". For example.
let oneWayMapJson = mapJsonWith fromJson id
Note that I have not tested this, just typed it in the Stack Overflow answer box, so some tweaking may be required. I don't have time to expand on this answer right now, but if you need more help than this rather Barebon answer, let me know and I'll try to give you more help sometime tomorrow.
source to share