Skip to content

Instantly share code, notes, and snippets.

Created May 6, 2023 14:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
An example on how to use SwaggerProvider: a type provider that automatically generates strongly-typed clients for openapi REST api's
#r "nuget: SwaggerProvider, Version=2.0.0-beta9"
open SwaggerProvider
open System
open System.Net.Http
type PetStore = OpenApiClientProvider<"">
let baseUri = Uri("")
let bearerToken = "01832905-a2db-4caa-bdab-5818ef5ec491"
let httpClient = new HttpClient(BaseAddress = baseUri)
httpClient.DefaultRequestHeaders.Authorization <- Headers.AuthenticationHeaderValue("Bearer", bearerToken)
let client = PetStore.Client(httpClient)
let createdPet =
id = Option.Some(123),
name = (sprintf "Pet:%A" (Guid.NewGuid())),
photoUrls = [||],
status = "available"
let retrieved =
|> (fun id -> client.GetPetById(id).Result)
printfn "Retrieved the newly created pet: %A" retrieved
let pets = client.FindPetsByStatus("available").Result
|> Seq.rev
|> Seq.take 3
|> Seq.iter (fun p -> printfn "%A" p.Name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment