Skip to content

Examples

Practical examples of using the OpenAPI Client Generator and generated clients.

Example 1: PetStore API

Generating the Client

cd OpenAPIDyalog
dotnet run -- ../pet-store/openapi.json ../pet-store/PetStore-Client

Using the Generated Client

⍝ Load the generated client
]LINK.Import # pet-store/PetStore-Client/APLSource

⍝ Create a client instance
client⎕NEW Client (baseURL:'https://petstore3.swagger.io/api/v3')

⍝ Find available pets
petsapi.pet.findPetsByStatus (client:client  status:'available')
'Available pets: ',≢pets

⍝ Get a specific pet
petapi.pet.getPetById (client:client  petId:1)
'Pet name: ',pet.name

⍝ Create a new pet
newPet⎕NEW models.Pet
newPet.name'Fluffy'
newPet.status'available'
resultapi.pet.addPet.syncDetailed (client:client  Pet:newPet)

:If result.statusCode200
    'Created pet with ID: ',⍕result.parsed.id
:Else
    'Error'
:EndIf

Next Steps