Csp.AspNetCoreProtobuf

Protobuf for ASP.NET Core

View on GitHub

Protobuf for ASP.NET Core | Web APIs

protobuf-net

A lighter way to transfer data through http.

Change Log


Supported Runtimes

Media Type

Runtime Installation

You can use the following command in the Package Manager Console:

For Server Side
Install-Package Csp.AspNetCore.Mvc.Protobuf
For Client Side
Install-Package Csp.Net.Http.Protobuf.Extensions
Package Version Downloads
Csp.AspNetCore.Mvc.Protobuf Nuget Nuget
Csp.Net.Http.Protobuf.Extensions Nuget Nuget

Sample Usage

Server Side

using Csp.AspNetCore.Mvc.Protobuf;
public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers()
            .AddProtobufSerializer(true); //true if use as default
}

Client Side

using Csp.Net.Http.Protobuf.Extensions;
...
var client = new HttpClient() { ... };
Get
var forecasts = await client.GetFromProtoAsync<WeatherForecast[]>("/weatherforecast");
Post
using var response = await client.PostAsProtoAsync("/weatherforecast", new WeatherForecast { ... });

using var stream = await response.Content.ReadAsStreamAsync();

var forecast = Serializer.Deserialize<WeatherForecast>(stream);