项目作者: Byndyusoft

项目描述 :
This package adds support for MessagePack formatting and content negotiation to System.Net.Http
高级语言: C#
项目地址: git://github.com/Byndyusoft/Byndyusoft.Net.Http.Formatting.MessagePack.git
创建时间: 2020-10-23T09:17:26Z
项目社区:https://github.com/Byndyusoft/Byndyusoft.Net.Http.Formatting.MessagePack

开源协议:MIT License

下载


Byndyusoft.Net.Http.Formatting.MessagePack

This package adds support for MessagePack formatting and content negotiation to System.Net.Http

(License)
Nuget NuGet downloads

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:

  1. using (var client = new HttpClient())
  2. {
  3. client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-msgpack"));
  4. var response = await client.GetAsync("http://localhost/api/products/1");
  5. response.EnsureSuccessStatusCode();
  6. var product = await response.Content.ReadAsAsync<ProductInfo>(new[]
  7. {
  8. new MessagePackMediaTypeFormatter()
  9. });
  10. }

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:

  1. // Save the ProductInfo model back to the API service
  2. await client.PutAsMessagePackAsync("http://localhost/api/products/1", product);
  3. await client.PostAsMessagePackAsync("http://localhost/api/products/1", product);

Installing

  1. dotnet add package Byndyusoft.Net.Http.Formatting.MessagePack

Contributing

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.

Prerequisites

Make sure you have installed all of the following prerequisites on your development machine:

General folders layout

src

  • source code

tests

  • unit-tests

example

  • example console application

Package development lifecycle

  • Implement package logic in src
  • Add or addapt unit-tests (prefer before and simultaneously with coding) in tests
  • Add or change the documentation as needed
  • Open pull request in the correct branch. Target the project’s master branch

Maintainers

github.maintain@byndyusoft.com