This package adds support for Protocol Buffers formatting and content negotiation to System.Net.Http
This package adds support for Protocol Buffers formatting and content negotiation to System.Net.Http
Protocol Buffers are Google’s language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler.
Byndyusoft.Net.Http.Formatting.ProtoBuf
actually depends on Microsoft.Net.Http
, and extends the HttpClient
with Protocol Buffers
features that you would likely need to talk to a RESTful service such as ASP.NET Web API.
Package operates in the System.Net.Http
namespace and adds some handy extension methods to HttpClient
and HttpContent
.
So for example:
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/protobuf"));
var response = await client.GetAsync("http://localhost/api/products/1");
response.EnsureSuccessStatusCode();
var product = await response.Content.ReadAsAsync<ProductInfo>(new[]
{
new ProtoBufMediaTypeFormatter()
});
}
If you tried to just use Microsoft.Net.Http
, the ReadAsAsync
method wouldn’t be available to you, and you’d only be able to read the content
as raw data such as bytes or string, and have to do the serializing / de-serializing yourself.
You also get extension methods to PUT / POST back to the service in ProtoBuf
format without having to do that yourself:
// Save the ProductInfo model back to the API service
await client.PutAsProtoBufAsync("http://localhost/api/products/1", product);
await client.PostAsProtoBufAsync("http://localhost/api/products/1", product);
dotnet add package Byndyusoft.Net.Http.Formatting.ProtoBuf
To contribute, you will need to setup your local environment, see prerequisites. For the contribution and workflow guide, see package development lifecycle.
A detailed overview on how to contribute can be found in the contributing guide.
Make sure you have installed all of the following prerequisites on your development machine:
src
tests
master
branch