Aller au contenu principal

Frameworks

.NET Core — Intégration Scell.io

Pas de SDK C# — HttpClient via IHttpClientFactory

Scell.io ne publie PAS de SDK C#/.NET officiel. En ASP.NET Core, intégrer via `IHttpClientFactory` (typed client recommandé). Enregistrer le client dans `Program.cs` via `services.AddHttpClient<ScellClient>()`, configurer le header `X-API-Key` dans la factory. Compatible .NET 8 LTS et 9. Utiliser `IConfiguration` pour la clé.

À retenir

  • Pas de SDK .NET officiel — `IHttpClientFactory`
  • Typed client `services.AddHttpClient<ScellClient>()`
  • Configuration via `appsettings.json` + `IConfiguration`
  • Compatible .NET 8 LTS et 9
  • Polly pour retry/circuit-breaker

Exemple de code

// Program.cs
builder.Services.AddHttpClient<ScellClient>(client => {
    client.BaseAddress = new Uri("https://api.scell.io/api/v1/");
    client.DefaultRequestHeaders.Add("X-API-Key", builder.Configuration["Scell:ApiKey"]);
});

public class ScellClient(HttpClient http) {
    public async Task<JsonElement> CreateInvoiceAsync(string buyer, decimal amount) {
        var payload = new {
            format = "factur-x",
            buyer = new { name = buyer, is_individual = true },
            lines = new[] { new { description = "Service", quantity = 1, unit_price = amount, vat_rate = 20.0 } }
        };
        var resp = await http.PostAsJsonAsync("invoices", payload);
        resp.EnsureSuccessStatusCode();
        return await resp.Content.ReadFromJsonAsync<JsonElement>();
    }
}

Voir aussi

Vos préférences cookies

Nous utilisons des cookies pour améliorer votre expérience. Les cookies essentiels sont toujours actifs. Politique cookies.