@@ -28,21 +28,21 @@ xscgen Kleer/doc.xsd --namespace=Kleer.Models --output Kleer/Models
2828
2929KleerClient is a wrapper around HttpClient that simplifies working with the Kleer API.
3030
31- * It sets up the BaseAddress and authentication headers (X-Token).
31+ - It sets up the BaseAddress and authentication headers (X-Token).
3232
33- * It provides helpers to build requests:
33+ - It provides helpers to build requests:
3434
35- * BuildRequest – bare request with default headers.
35+ - BuildRequest – bare request with default headers.
3636
37- * BuildXmlRequest<T > – request with XML-serialized content from a model.
37+ - BuildXmlRequest<T > – request with XML-serialized content from a model.
3838
39- * BuildBinaryRequest – request for file uploads (byte array or stream).
39+ - BuildBinaryRequest – request for file uploads (byte array or stream).
4040
41- * It provides async send methods:
41+ - It provides async send methods:
4242
43- * SendAsync(HttpRequestMessage) – returns raw HttpResponseMessage.
43+ - SendAsync(HttpRequestMessage) – returns raw HttpResponseMessage.
4444
45- * SendAsync<T >(HttpRequestMessage) – sends a request and deserializes the XML response into a model.
45+ - SendAsync<T >(HttpRequestMessage) – sends a request and deserializes the XML response into a model.
4646
4747Example usage:
4848
@@ -60,19 +60,39 @@ var request = KleerClient.BuildXmlRequest(HttpMethod.Post, "event/approve", data
6060var result = await client .SendAsync <Ok >(request );
6161```
6262
63+ Note that you might want to limit the number of connections to Kleer if you do many concurrent calls, in order to avoid ` 429 - Too many requests ` .
64+ Here is an example of how to register the HttpClient if you are using a HttpClientFactory to create the client(s):
65+
66+ ``` csharp
67+ services .AddHttpClient (" Kleer" , client =>
68+ {
69+ client .Timeout = TimeSpan .FromMinutes (5 );
70+ }).ConfigurePrimaryHttpMessageHandler (() => new HttpClientHandler
71+ {
72+ MaxConnectionsPerServer = 10 // Or lower/higher depending on your service and deployment strategy
73+ })
74+ .AddPolicyHandler (HttpPolicyExtensions
75+ .HandleTransientHttpError ()
76+ .OrResult (r => r .StatusCode == HttpStatusCode .TooManyRequests )
77+ .WaitAndRetryAsync (
78+ retryCount : 5 ,
79+ sleepDurationProvider : retryAttempt =>
80+ TimeSpan .FromSeconds (Math .Pow (2 , retryAttempt ))));
81+ ```
82+
6383## KleerXmlSerializer
6484
6585The Kleer API’s schema is defined via XSD, and ` xscgen ` generates C# models decorated with ` [XmlType] ` .
6686However, ` xscgen ` also generates duplicate ` *2Redefinition ` classes for schema redefinitions, which can cause the built-in ` XmlSerializer ` to fail.
6787
6888** ` KleerXmlSerializer ` ** works around this by:
6989
70- * Automatically renaming all ` *2Redefinition ` classes to unique names at runtime.
71- * Caching ` XmlSerializer ` instances per type (and per assembly override set) for performance.
72- * Serializing with settings tuned for the Kleer API:
73- * UTF-8 encoding without BOM.
74- * No XML declaration (` <?xml ...?> ` ).
75- * Suppressed ` xmlns:xsi ` / ` xmlns:xsd ` namespace attributes.
90+ - Automatically renaming all ` *2Redefinition ` classes to unique names at runtime.
91+ - Caching ` XmlSerializer ` instances per type (and per assembly override set) for performance.
92+ - Serializing with settings tuned for the Kleer API:
93+ - UTF-8 encoding without BOM.
94+ - No XML declaration (` <?xml ...?> ` ).
95+ - Suppressed ` xmlns:xsi ` / ` xmlns:xsd ` namespace attributes.
7696
7797Typically, you do not need to use ` KleerXmlSerializer ` directly, it is used internally by ` KleerClient ` for both requests and responses.
7898But you can use it if you just want to work with models outside of HTTP:
0 commit comments