C# / .NET

Barcode Generator API for C# and .NET

Generate barcodes in C# with HttpClient - no NuGet barcode package or per-developer SDK licence.

One GET request returns Code 128, EAN, UPC, GS1-128, DataMatrix or QR codes as SVG, PNG, PDF or EPS.

Fits ASP.NET Core minimal APIs, worker services and Azure Functions without native dependencies.

GS1 Application Identifiers are validated server-side; the free tier includes 1,000 calls per month.

Commercial .NET barcode SDKs are licensed per developer and pull rendering into your process; free ones vary widely in GS1 correctness. Consuming a REST API instead means the only moving part in your codebase is HttpClient, which you already use, and pricing follows API volume rather than team size.

The examples below target .NET 6+ and use the recommended IHttpClientFactory-friendly shape: a small typed client you can register in DI and inject wherever labels, invoices or shipping documents are produced.

Setup

# no package needed - HttpClient is part of the BCL

Generate barcodes in C# / .NET

using System.Net.Http;

public sealed class BarGenClient
{
    private readonly HttpClient _http;

    public BarGenClient(HttpClient http, string apiKey)
    {
        _http = http;
        _http.BaseAddress = new Uri("https://api.bargen.pro/v1/");
        _http.DefaultRequestHeaders.Add("X-API-Key", apiKey);
    }

    public async Task<byte[]> GenerateAsync(
        string type, string data, string format = "svg",
        IDictionary<string, string>? options = null, CancellationToken ct = default)
    {
        var query = new List<string> {
            $"data={Uri.EscapeDataString(data)}",
            $"format={format}",
        };
        if (options != null)
            foreach (var (k, v) in options)
                query.Add($"{k}={Uri.EscapeDataString(v)}");

        var resp = await _http.GetAsync($"barcode/{type}?{string.Join("&", query)}", ct);
        resp.EnsureSuccessStatusCode();
        return await resp.Content.ReadAsByteArrayAsync(ct);
    }
}

// Usage:
var client = new BarGenClient(new HttpClient(), "YOUR_API_KEY");

// A Code 128 barcode as SVG
var svg = await client.GenerateAsync("code128", "ORDER-2026-0042");
await File.WriteAllBytesAsync("order.svg", svg);

// A GS1-128 barcode - Application Identifiers validated server-side
var gs1 = await client.GenerateAsync("gs1-128", "(01)09501101530003(17)261231(10)AB123");

// A QR code as PNG with custom colour and scale
var png = await client.GenerateAsync("qrcode", "https://bargen.pro", "png",
    new Dictionary<string, string> { ["color"] = "1a1a2e", ["scale"] = "4" });

Bulk generation with the batch endpoint

// Up to 50 barcodes in one request via the batch endpoint
var payload = new
{
    codes = new object[]
    {
        new { type = "code128", data = "SKU-0001" },
        new { type = "code128", data = "SKU-0002" },
        new { type = "qrcode",  data = "https://example.com/p/1" },
    },
    options = new { format = "svg" },
};
var resp = await _http.PostAsJsonAsync("barcode/batch", payload);
resp.EnsureSuccessStatusCode();

Frequently asked questions

How should I register this in ASP.NET Core dependency injection?

Use a typed client: services.AddHttpClient<BarGenClient>(c => { c.BaseAddress = new Uri("https://api.bargen.pro/v1/"); c.DefaultRequestHeaders.Add("X-API-Key", config["BarGen:ApiKey"]); }). IHttpClientFactory then manages connection pooling and lifetimes for you.

Does this work in Azure Functions and AWS Lambda for .NET?

Yes. There is no native rendering dependency, so deployment packages stay small and there are no platform-specific binaries - the same code runs on Windows, Linux containers and serverless .NET runtimes.

How does pricing compare to a commercial .NET barcode SDK?

SDKs are typically licensed per developer; BarGen is priced by API volume only. The free tier covers 1,000 calls/month; Pro is $29/month for 10,000 and Business $79/month for 100,000 with a 99.9% SLA. Ten developers or one - the price is the same.

Can I embed the SVG output in a PDF invoice?

Yes. SVG, PDF and EPS outputs are vector formats, so they stay sharp at any print resolution. Libraries like QuestPDF accept SVG directly, and the PDF output can be composed into print pipelines as-is.

API basics

Endpoint
GET api.bargen.pro/v1/barcode/{type}
Auth
X-API-Key header
Output
SVG, PNG, PDF, EPS
Formats
25 barcode types incl. GS1 and postal
Free tier
1,000 calls/month
Full API reference

Code on GitHub

Runnable examples for every language live in the public docs repository.

bargen-pro/bargen-api-docs

Start generating barcodes from C# / .NET

Free tier with 1,000 API calls per month. No credit card required.