A Quick F# Load Test Script

April 23, 2024    Development .Net FSharp

A Quick F# Load Test Script

Here’s a quick way to hit your api with a lot of requests in parallel using F# .

Requirements

  • FsHttp
  • A way to run F#
    • VS Code is helpful with the F# Ionide Extension
      • create a .fsx file in VS Code, highlight all and alt-enter or click the play button

Code

#r "nuget: FsHttp"
open FsHttp

[|1..1000|]
 |> Array.Parallel.map (fun x ->
       (x, http {
           GET "https://{your-url}/api/"
           //AuthorizationBearer ""
           // add a custom header if you need: this is needed for Azure Functions header "X-Functions-Key" ""
           body 
           jsonSerialize x
       }
       |> Request.send)
   ) 
   |> Seq.iter (fun (org, response) -> 
       let contentValue = Response.toString (Some 9000) response
       printfn "Request: %A | Status Code: %A | Response Content: %A" org response.statusCode contentValue
   )