If you want to return an HTTP 200 response using JSON and set the HTTP headers in Suave, you can use the Writers.setHeader function:
Writers.setHeader "Access-Control-Allow-Credentials" "true" >=> Writers.setHeader "Access-Control-Allow-Headers:Content-Type" "Accept" >=> Writers.setHeader "Access-Control-Allow-Methods" "GET, POST, PUT, DELETE, OPTIONS" >=> Writers.setHeader "Access-Control-Allow-Origin" "" >=> Successful.OK (movies |> Json.serialize |> Json.format)
All of this is an expression that creates a WebPart , which you can then compose with other web parts using the functions provided by Suave. Therefore, if you want to map the template before setting the headers, you should use something like:
let php = request (fun r -> match r.queryParam "playerName" with | Choice1Of2 name -> Writers.setHeader "Access-Control-Allow-Credentials" "true" >=> Writers.setHeader "Access-Control-Allow-Headers:Content-Type" "Accept" >=> Writers.setHeader "Access-Control-Allow-Methods" "GET, POST, PUT, DELETE, OPTIONS" >=> Writers.setHeader "Access-Control-Allow-Origin" "" >=> Successful.OK (movies |> Json.serialize |> Json.format) | Choice2Of2 msg -> BAD_REQUEST msg)
As you set the CORS headers, this snippet can also help .
source share