#1 Re: mORMot 2 » OpenAPI client working example? Also with OAuth2? » 2025-05-05 13:26:57

Thank you so much flydev, you are amazing! :-)

#2 Re: mORMot 2 » OpenAPI client working example? Also with OAuth2? » 2025-04-29 10:30:12

Thank you flydev! So to set headers manually should I just send the request using TJsonClient.Http.Request?

#3 Re: mORMot 2 » OpenAPI client working example? Also with OAuth2? » 2025-04-22 10:23:11

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');

#4 mORMot 2 » OpenAPI client working example? Also with OAuth2? » 2025-04-17 09:52:19

jiwi
Replies: 6

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!

Board footer

Powered by FluxBB