You are not logged in.
Hello,
I've found the mORMot 2 OpenAPI client generator (which is by the way, awesome!) and managed to generate the client/dto units, but I'm stuck trying create an actual working client.
Does anybody have an example, maybe for the PetStore swagger demo?
Also, for the API that I'll be using I'll need to implement authorization with OAuth2 client_credentials flow (https://auth0.com/docs/get-started/auth … tials-flow). Are there any working examples for that maybe, or can someone point me in the right direction?
Thanks a lot!
Offline
Thank you ab! Could you please elaborate on how do I add the bearer token to TJsonClient? I have found there is a TJsonClient.HttpOptions.AuthorizeBearer() call, is that it?
Also, if I want to send requests to the server directly, should I use TJsonClient.Http.Request?
How can I send application credentials like client secret/private key/etc.? Is there an option for that among TJsonClient parameters?
I have some example code, I tried to convert the PetStore swagger example, does this look okay?
const
PetID = 61341;
CategoryID = 61341;
TagID = 61341;
var
JsonClient: TJsonClient;
Client: TPetStoreClient;
Pet: TPet;
Tag: TTag;
begin
JsonClient := TJsonClient.Create('https://petstore.swagger.io/v2', '', 0);
Client := TPetStoreClient.Create(JsonClient);
Pet.Id := PetID;
Pet.Name := 'Josephine';
Pet.Status := epAvailable;
Pet.Category.Id := CategoryID;
Pet.Category.Name := 'Terrier Dogs';
Tag.Id := TagID;
Tag.Name := 'Terrier';
SetLength(Pet.Tags, 1);
Pet.Tags[0] := Tag;
SetLength(Pet.PhotoUrls, 1);
Pet.PhotoUrls[0] := 'http://dummy.com/dog.png';
//Add new pet
Client.AddPet(Pet);
//Get pet info
Pet := Client.GetPetById(PetID);
//Delete the newly created pet
Client.DeletePet(PetID, 'special-key');
Offline
Just use `SetBearer`, you can of course just set header manually.
Offline
Thank you flydev! So to set headers manually should I just send the request using TJsonClient.Http.Request?
Offline
I published a small example on github: flydev-fr/mormot2-jsonclient
and small comments project1.lpr#L29-L38
look how the client is used in `petstore.client` (generated by mopenapi)
Check request headers:
Last edited by flydev (2025-04-29 11:43:07)
Offline
Thank you so much flydev, you are amazing! :-)
Offline