Sayfayı Yazdır | Pencereyi Kapat

CLRest Kullanımı

Nereden Yazdırıldığı: Clomosy | Forum
Kategori: Genel Programlama
Forum Adı: Clomosy ile değişken kullanımı
Forum Tanımlaması: TRObject dili ile değişken tanımlaması ve ekranda gösterme
URL: https://forum.clomosy.com.tr/forum_posts.asp?TID=1222
Tarih: 11 Kasım 2025 Saat 16:08
Program Versiyonu: Web Wiz Forums 12.07 - https://www.webwizforums.com


Konu: CLRest Kullanımı
Mesajı Yazan: M-Guney
Konu: CLRest Kullanımı
Mesaj Tarihi: 11 Kasım 2025 Saat 11:12
Unitler arasında temiz ve performanslı bir şekilde nasıl TCLResti kullanabilirim 30 dan fazla Api bağlantım var ve performans yükü bindirmek istemiyorum. https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" rel="nofollow - https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon="{"version":"2024.11.0","token":"439455f3e46c40b98dbd42a2f1a954d8","r":1,"server_timing":{"name":{"cfCacheStatus":true,"cfEdge":true,"cfExtPri":true,"cfL4":true,"cfOrigin":true,"cfSpeedBrain":true},"location_startswith":null}}" crossorigin="anonymous">



Cevaplar:
Mesajı Yazan: Emr.Erkmn
Mesaj Tarihi: 11 Kasım 2025 Saat 11:19
Merhaba Güney, 
Uygulamamız da bir tame birim oluşturalım yani kütüphane oluşturalım (uApı.pas ya da uApiLib). 
Bu yeni unit uygulamanın API yöneticisi olacak
Yeni unitte oluşturalın prosedürile daha yüksek bir performan sergileyebiliriz


https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" rel="nofollow - https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon="{"version":"2024.11.0","token":"439455f3e46c40b98dbd42a2f1a954d8","r":1,"server_timing":{"name":{"cfCacheStatus":true,"cfEdge":true,"cfExtPri":true,"cfL4":true,"cfOrigin":true,"cfSpeedBrain":true},"location_startswith":null}}" crossorigin="anonymous">


Mesajı Yazan: M-Guney
Mesaj Tarihi: 11 Kasım 2025 Saat 11:21
uDataLib oluşturdum

void GetConnectDB(TCRest : TCLRest)
{
  try
    if (Clomosy.AppPlatform == 0) // is Windows
    {
      TCRest.BaseURL = 'http://MY-API/';
    }else {
      TCRest.BaseURL = ' https://MY-URL.com.tr/" rel="nofollow - https://MY-URL.com.tr/ ';
    }
    //TCRest.AddHeader('Authorization','Bearer ' + Clomosy.GlobalVariableString);
    TCRest.Execute;
    TCRest.ClearParams;
    TCRest.ClearBody;
  except
  ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
  }
}



Mesajı Yazan: M-Guney
Mesaj Tarihi: 11 Kasım 2025 Saat 11:22
Sonrasında alttaki şekilde çağırdım 
void GetUserPrivilegesV
{
  TableName = TClProButton(MainForm.Clsender).clTagStr;
  OrderID = TClProButton(MainForm.Clsender).clTagInt;
 //TCRest.ClearParams;
  uDataLib.GetConnectDB(TCRest);
  TCRest.Resource = 'privileges';
  TCRest.Accept = 'application/json';
  TCRest.Method = rmGET;
  
  TCRest.AddHeader('Authorization','Bearer ' + Clomosy.GlobalVariableString);
  TCRest.OnCompleted = 'GetUserPrivilegesCompletedV';
  TCRest.ExecuteAsync;
  TCRest.ClearBody;
  
  
}
https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" rel="nofollow - https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon="{"version":"2024.11.0","token":"439455f3e46c40b98dbd42a2f1a954d8","r":1,"server_timing":{"name":{"cfCacheStatus":true,"cfEdge":true,"cfExtPri":true,"cfL4":true,"cfOrigin":true,"cfSpeedBrain":true},"location_startswith":null}}" crossorigin="anonymous">


Mesajı Yazan: M-Guney
Mesaj Tarihi: 11 Kasım 2025 Saat 11:23
Fakat bir alt unitte ise hem geç çalışıyor hem de ne kadar istesem de showMessage ile tcl.response u gösteremiyorum

void GetOrderDetailsCompletedV
var
  jsonResponse, NoteString: String;
  Arr : TCLJSONArray;
{
  ShowMessage('query is finished');
  jsonResponse = TCRest.Response;
  ShowMessage('Json Response: '+ jsonResponse);
  Arr = TCLJSONArray.Create;
Arr = TCLJSONArray.CreateFromJSON(jsonResponse);
  if(jsonResponse == ''){
    ShowMessage('Sipariş Detaylar listesi boş herhangi bir sipariş yok.');
  }else{
    noteMemo.Text = Clomosy.CLParseJSON(jsonResponse, '0.note');
    AmountValueLbl.Text = Clomosy.CLParseJSON(jsonResponse, '0.total_price') + 'TL';
    DetailsPnlV(Arr.Count, jsonResponse);
  }
}

void GetOrderDetailsV
{
  ShowMessage('OrderID will be query: '+IntToStr(OrderID));
  TCRest.ClearParams;
  uDataLib.GetConnectDB(TCRest);
  TCRest.Resource = 'orderDetails/' + IntToStr(OrderID);
  TCRest.Accept = 'application/json';
  TCRest.Method = rmGET;
  
  TCRest.AddHeader('Authorization','Bearer ' + Clomosy.GlobalVariableString);
  TCRest.OnCompleted = 'GetOrderDetailsCompletedV';
  TCRest.ExecuteAsync;
  TCRest.ClearBody;
  
}
https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" rel="nofollow - https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon="{"version":"2024.11.0","token":"439455f3e46c40b98dbd42a2f1a954d8","r":1,"server_timing":{"name":{"cfCacheStatus":true,"cfEdge":true,"cfExtPri":true,"cfL4":true,"cfOrigin":true,"cfSpeedBrain":true},"location_startswith":null}}" crossorigin="anonymous">


Mesajı Yazan: Emr.Erkmn
Mesaj Tarihi: 11 Kasım 2025 Saat 11:46
Sorunun iki kaynağı var gibi gözüküyor, 
uDataLib.GetConnectDB için de mantık hatası ve  executeAsync  https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" rel="nofollow - https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon="{"version":"2024.11.0","token":"439455f3e46c40b98dbd42a2f1a954d8","r":1,"server_timing":{"name":{"cfCacheStatus":true,"cfEdge":true,"cfExtPri":true,"cfL4":true,"cfOrigin":true,"cfSpeedBrain":true},"location_startswith":null}}" crossorigin="anonymous">

void GetConnectDB(TCRest : TCLRest)
{
  try
  {
    if (Clomosy.AppPlatform == 0) // is Windows
    {
      TCRest.BaseURL = 'http://MY-API/';
    }else {
      TCRest.BaseURL = ' https://MY-URL.com.tr/" rel="nofollow - https://MY-URL.com.tr/ ';
    }
  }
  except
  {
    ShowMessage('GetConnectDB Hatası: '+LastExceptionMessage);
  }
}
Execute komutu önce çalışıyor ve yavaşlatıyor. 
Asıl işi yapacak olan ExecuyeAsync komunu çalıştırmayı dene. 
GetConnectDB sadece basel url olarak ayarla,

kod da TclREst'i iki prosedürde de asenkron olarak kullanışmış, 


void GetOrderDetailsV
var
  jsonResponse, NoteString: String;
  Arr : TCLJSONArray;
{
  ShowMessage('OrderID will be query: '+IntToStr(OrderID));
  TCRest.ClearParams;
  
  uDataLib.GetConnectDB(TCRest);
  
  TCRest.Resource = 'orderDetails/' + IntToStr(OrderID);
  TCRest.Accept = 'application/json';
  TCRest.Method = rmGET;
  
  TCRest.AddHeader('Authorization','Bearer ' + Clomosy.GlobalVariableString);
  
  try
    TCRest.Execute;
  except
    ShowMessage('API Hatası (Execute): ' + LastExceptionMessage);
  }

  jsonResponse = TCRest.Response;
  ShowMessage('Json Response: '+ jsonResponse); 
  
  if(jsonResponse == ''){
    ShowMessage('Sipariş Detaylar listesi boş herhangi bir sipariş yok.');
  }else{
    try
      Arr = TCLJSONArray.CreateFromJSON(jsonResponse);
      noteMemo.Text = Clomosy.CLParseJSON(jsonResponse, '0.note');
      AmountValueLbl.Text = Clomosy.CLParseJSON(jsonResponse, '0.total_price') + 'TL';
      DetailsPnlV(Arr.Count, jsonResponse);
    except
      ShowMessage('JSON Ayrıştırma Hatası: ' + LastExceptionMessage);
    }
  }
}





Sayfayı Yazdır | Pencereyi Kapat

Forum Software by Web Wiz Forums® version 12.07 - https://www.webwizforums.com
Copyright ©2001-2024 Web Wiz Ltd. - https://www.webwiz.net