Ana içeriğe geç

HTTP Task (Type: 6)

HTTP Task, harici web servislerine HTTP istekleri göndermek için kullanılan görev türüdür. Bu görev türü ile REST API'lere, web servislerine ve diğer HTTP endpoint'lerine çağrı yapabilirsiniz.

Görev Tanımı

Schema: task-definition.schema.json

{
"key": "get-user-info",
"version": "1.0.0",
"domain": "core",
"flow": "sys-tasks",
"flowVersion": "1.0.0",
"tags": ["users", "lookup", "information"],
"attributes": {
"type": "6",
"config": {
"url": "http://api.example.com/api/users/{userId}",
"method": "GET",
"headers": {
"Content-Type": "application/json"
},
"timeoutSeconds": 30,
"validateSsl": true
}
}
}

Konfigürasyon Alanları

AlanTipZorunluVarsayılanAçıklama
urlstringEvet-Hedef URL
methodstringEvet-HTTP metodu (GET, POST, PUT, DELETE, PATCH)
headersobjectHayırnullHTTP header'ları
bodyobjectHayırnullRequest body (GET dışında)
timeoutSecondsintegerHayır30İstek timeout süresi (saniye, minimum: 1)
validateSslbooleanHayırtrueSSL sertifika doğrulaması
acceptedStatusCodesstring[]Hayır-Başarılı kabul edilecek HTTP hata kodları. Exact kod ("403", "404") ve wildcard pattern ("4xx", "40x", "5xx") destekler. Eşleşen status code'larda task başarılı sayılır ve ErrorBoundary tetiklenmez.

Property Erişimi

HttpTask sınıfındaki property'ler ve setter metodları:

PropertySetter MetoduAçıklama
UrlSetUrl(string url)Hedef URL'i değiştirir
MethodDoğrudan atamaHTTP metodunu değiştirir
HeadersSetHeaders(Dictionary<string, string?> headers)Tüm header'ları set eder
-AddHeader(string key, string? value)Tekil header ekler/günceller
-RemoveHeader(string key)Tekil header kaldırır
BodySetBody(dynamic body)Request body'yi set eder
TimeoutSecondsRead-onlyTanım dosyasında ayarlanır
ValidateSSLRead-onlyTanım dosyasında ayarlanır
AcceptedStatusCodesRead-onlyTanım dosyasında ayarlanır

Standart Yanıt

{
"Data": { },
"StatusCode": 200,
"IsSuccess": true,
"ErrorMessage": null,
"Headers": {
"content-type": "application/json",
"content-length": "156"
},
"Metadata": {
"Url": "https://api.example.com/users",
"Method": "POST",
"ReasonPhrase": "OK"
},
"ExecutionDurationMs": 245,
"TaskType": "Http"
}

Başarılı Yanıt

  • IsSuccess: true
  • StatusCode: 2xx HTTP status kodu
  • Data: Deserialize edilmiş response verisi
  • Headers: Response header'ları
  • ExecutionDurationMs: İstek süresi

Hatalı Yanıt

  • IsSuccess: false
  • StatusCode: HTTP hata kodu (4xx, 5xx)
  • ErrorMessage: Hata açıklaması
  • Metadata: Ek hata bilgileri

Hata Senaryoları

HTTP Hatası (4xx, 5xx)

{
"IsSuccess": false,
"StatusCode": 404,
"ErrorMessage": "HTTP request failed with status 404: Not Found",
"Metadata": {
"Url": "https://api.example.com/users/999",
"Method": "GET",
"ReasonPhrase": "Not Found",
"ResponseContent": "{\"error\": \"User not found\"}"
}
}

Network Hatası

{
"IsSuccess": false,
"ErrorMessage": "The remote name could not be resolved: 'invalid-domain.com'",
"Metadata": {
"Url": "https://invalid-domain.com/api",
"Method": "POST"
}
}

Timeout Hatası

{
"IsSuccess": false,
"ErrorMessage": "HTTP request was cancelled",
"Metadata": {
"Url": "https://slow-api.com/endpoint",
"Method": "GET",
"Cancelled": true
}
}

Sık Karşılaşılan Sorunlar

ProblemÇözüm
SSL Certificate ErrorvalidateSsl: false ayarlayın (sadece development için)
TimeouttimeoutSeconds değerini artırın
401 UnauthorizedAuthorization header'ını kontrol edin
JSON Parse ErrorResponse content-type ve formatını kontrol edin