This is an F# script that posts a Post like object to the json placeholder API and deserializes the json response to a Post.
you can copy into a file and run it like this:
dotnet fsi ./filename.fsx
#r"nuget: FsHttp"// specify the http library// open the required namespacesopenFsHttpopenFsHttp.DslCEopenSystem.Text.Json// define the shape of the data// these are known as Records in F#typePost={userId:intid:inttitle:stringbody:string}// In F# records can't have null values for most types// so we use an anonymous record (`{| |}` instead of `{}`)// because we don't have an id value yetletpayload=JsonSerializer.Serialize({|userId=1title="Sample"body="Content"|})letresponse=// declare the requesthttp{POST"https://jsonplaceholder.typicode.com/posts"bodyjsonpayload}// send the request, it can also be done asynchronously|>Request.send// get the stream back (rather than downloading the response in bytes/string|>Response.toStream// deserialize it using .NET base class library classes like JsonSerializer|>JsonSerializer.Deserialize<Post>// you can now check the response in the consoleprintfn"%A"response
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is an F# script that posts a Post like object to the json placeholder API and deserializes the json response to a Post.
you can copy into a file and run it like this:
dotnet fsi ./filename.fsx