This package adds support for MessagePack formatting and content negotiation to System.Net.Http
This package adds support for MessagePack formatting and content negotiation to System.Net.Http
MessagePack is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON. But it’s faster and smaller.
Small integers are encoded into a single byte, and typical short strings require only one extra byte in addition to the strings themselves.
Byndyusoft.Net.Http.Formatting.MessagePack
actually depends on Microsoft.Net.Http
, and extends the HttpClient
with MessagePack
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/x-msgpack"));
var response = await client.GetAsync("http://localhost/api/products/1");
response.EnsureSuccessStatusCode();
var product = await response.Content.ReadAsAsync<ProductInfo>(new[]
{
new MessagePackMediaTypeFormatter()
});
}
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 MessagePack
format without having to do that yourself:
// Save the ProductInfo model back to the API service
await client.PutAsMessagePackAsync("http://localhost/api/products/1", product);
await client.PostAsMessagePackAsync("http://localhost/api/products/1", product);
dotnet add package Byndyusoft.Net.Http.Formatting.MessagePack
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