🔷

.NET Core OCR — Minimal API Integration

.NET Minimal API for Cargoffer OCR document extraction.

Minimal API

csharp
using System.Net.Http.Headers;
using System.Text.Json;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapPost("/ocr/extract", async (IFormFile file) =>
{
    using var client = new HttpClient();
    client.DefaultRequestHeaders.Authorization =
        new AuthenticationHeaderValue("Bearer",
            builder.Configuration["Ocr:ApiKey"]);

    using var content = new MultipartFormDataContent();
    await using var stream = file.OpenReadStream();
    content.Add(new StreamContent(stream), "file", file.FileName);

    var upload = await client.PostAsync(
        "https://ocr.cargoffer.com/api/upload", content);
    var job = (await upload.Content
        .ReadFromJsonAsync<JsonElement>()).GetProperty("job").GetString();

    var analyze = await client.PostAsync(
        $"https://ocr.cargoffer.com/api/analyze/{job}", null);
    return Results.Ok(await analyze.Content
        .ReadFromJsonAsync<JsonElement>());
});

app.Run();

Ready to try it?

Start Free →