i'm begining with Suave and F#. I'm trying to pass a json serialized object in my webpart to get it in my response.
In php i have this
<?php
header('Access-Control-Allow-Credentials:true');
header('Access-Control-Allow-Headers:Content-Type, Accept');
header('Access-Control-Allow-Methods:GET, POST, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Origin:*');
?>
{
"player1Key":"hdegftzj25",
"gameKey":"aegfhzkfszl74852"
}
and with this i get my json object, then i tried to do the same with Suave and Newtonsoft.Json
type gameCreate= {
player1Key : string
gameKey: string
}
let create= { player1Key = "BadBoys2"; gameKey = "zLUGgtrht4456" }
let json = Newtonsoft.Json.JsonConvert.SerializeObject(create)
//OK (acc |> Json.serialize |> Json.format )
let php =
request (fun r ->
match r.queryParam "playerName" with
| Choice1Of2 name -> OK (movies |> Json.serialize(json) |> Json.format(json))
//|> Response.response(Json.toJson(info))
//|> OK
| Choice2Of2 msg -> BAD_REQUEST msg)
let webPart =
choose [
path "/" >=> (OK "Home")
path "/elm/api/create.php" >=> php
]
startWebServer defaultConfig webPart
So i can create and serialize a json object but i don't know how to pass it as http response in my web part and with the above code i keep on getting error on my expressions type in my let php
Json.format
is, or where you got it from, but you need to pass a string toOK
. – BrittainChoice1Of2
case looks very much off, for any sane implementation ofJson.serialize/format
I can think of. – Brittainmovies
? That isn't defined anywhere. – Extravagancy