A lighter way to transfer data through http.
- Csp.AspNetCore.Mvc.Protobuf
- .Net Core 3.1+
- Csp.Net.Http.Protobuf.Extensions
- .Net Standard 2.1+
- application/x-protobuf
You can use the following command in the Package Manager Console:
Install-Package Csp.AspNetCore.Mvc.Protobuf
Install-Package Csp.Net.Http.Protobuf.Extensions
Package | Version | Downloads |
---|---|---|
Csp.AspNetCore.Mvc.Protobuf | ||
Csp.Net.Http.Protobuf.Extensions |
using Csp.AspNetCore.Mvc.Protobuf;
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers()
.AddProtobufSerializer(true); //true if use as default
}
using Csp.Net.Http.Protobuf.Extensions;
...
var client = new HttpClient() { ... };
var forecasts = await client.GetFromProtoAsync<WeatherForecast[]>("/weatherforecast");
using var response = await client.PostAsProtoAsync("/weatherforecast", new WeatherForecast { ... });
using var stream = await response.Content.ReadAsStreamAsync();
var forecast = Serializer.Deserialize<WeatherForecast>(stream);