Asp.Net Core Support for Dahomey.Cbor
- Asp.net core 2.1, 2.2, 3.0 and 3.1 CBOR formatters
You can enable Dahomey.Cbor as a CBOR formatter in ASP.NET Core 2.1 or 2.2 by using the Nuget package Dahomey.Cbor.AspNetCore. To enable it, add the extension method AddDahomeyCbor(CborOptions options = null)
to the AddMvc()/AddControllers()
call in ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
CborOptions options = new CborOptions();
services.AddMvc()
.AddDahomeyCbor(options);
}
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
CborOptions options = new CborOptions();
services.AddControllers()
.AddDahomeyCbor(options);
}
If an incoming HTTP request holds the following headers:
Content-Type
with the valueapplication/cbor
: the Request body will be deserilized in CBOR.Accept
with the valueapplication/cbor
: the Response body will be serialized in CBOR.
If the headers are missing, the default JSON formatters will be used.