Exploring Neon as a Serverless Postgres Alternative for .NET Applications on Azure - Part 1 (Simple ASP.NET Core on App Service)10 lut 2025
Blog | programowanie | .net | c# | azure | IT
My first post on working with NDJSON stream in .NET was a result of a use case I needed to satisfy in one of the projects I'm involved with (and it worked great). As a result, I've received some questions on this subject. I've already answered the most common one on this blog, but there were a couple more that were really frequent. So I've decided I'm going to add a few more posts to this series:
When I was writing my first post about NDJSON, I didn't know there were services out there using it as an input format. The fact is that they do, which creates a need for a way to stream NDJSON with HttpClient. The natural expectation is to be able to POST an async stream, preferably with simple and elegant code.
async IAsyncEnumerable<WeatherForecast> streamWeatherForecastsAsync()
{
for (int daysFromToday = 1; daysFromToday <= 10; daysFromToday++)
{
WeatherForecast weatherForecast = await GetWeatherForecastAsync(daysFromToday).ConfigureAwait(false);
yield return weatherForecast;
};
};
using HttpClient httpClient = new();
using HttpResponseMessage response = await httpClient.PostAsync("...",
new NdjsonAsyncEnumerableContent<WeatherForecast>(streamWeatherForecastsAsync())
).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
The way to achieve the elegancy in the above snippet is through the custom implemen
noreply@blogger.com (Tomasz Pęczek)