{"id":26491901,"url":"https://github.com/alphacloud/messagepack","last_synced_at":"2026-03-17T14:08:34.225Z","repository":{"id":34053342,"uuid":"144908132","full_name":"alphacloud/messagepack","owner":"alphacloud","description":"MessagePack formatters for ASP.NET Core MVC","archived":false,"fork":false,"pushed_at":"2025-01-21T17:40:46.000Z","size":281,"stargazers_count":9,"open_issues_count":10,"forks_count":3,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-02-22T07:49:10.769Z","etag":null,"topics":["asp-net-core","content-negotiation","httpclient","message-pack","messagepack","messagepack-formatters","msgpack","mvc-core","mvc-formatters","net-core","serialization"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alphacloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-15T22:07:32.000Z","updated_at":"2024-10-13T06:52:33.000Z","dependencies_parsed_at":"2024-03-13T21:29:06.669Z","dependency_job_id":"e729e16c-5376-45bd-88ef-b2b28fca7082","html_url":"https://github.com/alphacloud/messagepack","commit_stats":null,"previous_names":["alphacloud/messagepack-mvc"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphacloud%2Fmessagepack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphacloud%2Fmessagepack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphacloud%2Fmessagepack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphacloud%2Fmessagepack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alphacloud","download_url":"https://codeload.github.com/alphacloud/messagepack/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244583173,"owners_count":20476233,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asp-net-core","content-negotiation","httpclient","message-pack","messagepack","messagepack-formatters","msgpack","mvc-core","mvc-formatters","net-core","serialization"],"created_at":"2025-03-20T08:51:09.004Z","updated_at":"2026-03-17T14:08:29.204Z","avatar_url":"https://github.com/alphacloud.png","language":"C#","readme":"# MessagePack Formatters for ASP.NET Core MVC and HttpClient\n\nAllows to use [MessagePack format](http://msgpack.org/) with ASP.NET Core MVC. If multiple formatters are configured,\ncontent negotiation is used to determine which formatter to use.\n\nThis library leverages [MessagePack-CSharp](https://github.com/neuecc/MessagePack-CSharp) library by Yoshifumi Kawai (a.k.a. neuecc).\n\n## Build status\n\n||Stable|Pre-release|\n|:--:|:--:|:--:|\n| Build                                   | [![Master](https://ci.appveyor.com/api/projects/status/jvcg5663lannifb9/branch/master?svg=true)](https://ci.appveyor.com/project/shatl/messagepack/branch/master) | [![PreRelease](https://ci.appveyor.com/api/projects/status/jvcg5663lannifb9?svg=true)](https://ci.appveyor.com/project/shatl/messagepack) |\n| NuGet ASP.NET Core MVC formatters       | [![NuGet](https://img.shields.io/nuget/v/Alphacloud.MessagePack.AspNetCore.Formatters.svg)](https://www.nuget.org/packages/Alphacloud.MessagePack.AspNetCore.Formatters) | [![NuGet](https://img.shields.io/nuget/vpre/Alphacloud.MessagePack.AspNetCore.Formatters.svg)](https://www.nuget.org/packages/Alphacloud.MessagePack.AspNetCore.Formatters/absoluteLatest) |\n| NuGet MediaTypeFormatter for HttpClient | [![NuGet](https://img.shields.io/nuget/v/Alphacloud.MessagePack.HttpFormatter.svg)](https://www.nuget.org/packages/Alphacloud.MessagePack.HttpFormatter) | [![NuGet](https://img.shields.io/nuget/vpre/Alphacloud.MessagePack.HttpFormatter.svg)](https://www.nuget.org/packages/Alphacloud.MessagePack.HttpFormatter/absoluteLatest) |\n\n\n## Packages\n* [ASP.NET Core MVC formatters](#aspnet-core-mvc-formatters)\n* [MediaTypeFormatter for HttpClient](#mediatypeformatter-for-httpclient)\n\n\n# ASP.NET Core MVC formatters\n\n## Installation\n\n```\nInstall-Packagge Alphacloud.MessagePack.AspNetCore.Formatters\n```\n\n\n## Features\n\n* Input formatter (decode MessagePack payload).\n* Output formatter (encode MessagePack payload).\n* Source link support (source code on demand in debugger).\n\n\n## Usage\n\n### Default configuration\n\nDefault configuration uses `application/x-msgpack` as media typeidentificator, `msgpack` as file name extension and `ContractlessStandardResolver`.\n\nAdd `services.AddMessagePack();` call to your `Startup.cs / ConfigureServices`\n```\npublic void ConfigureServices(IServiceCollection services)\n{\n    services.AddMessagePack();\n    // ...\n}\n```\n\n#### MVC Core (ASP.NET Core 2.x)\n\nWhen using minimal MVC configuration (e.g. in WebAPI service) only base services are added by default.\nYou are responsible for configuring each of the service you are going to use.\n\n**Note:** order of formatters is important - in the example below Json will be default serializer,\nunless MVC is configured to reject requests with unsupported media type.\n\n```\npublic void ConfigureServices(IServiceCollection services)\n{\n  services.AddMvcCore(options =\u003e\n    {\n        // ...\n    })\n    .AddDataAnnotations()\n    .AddJsonOptions(options =\u003e\n    {\n        options.SerializerSettings.Culture = CultureInfo.InvariantCulture;\n        options.SerializerSettings.Formatting = Formatting.None;\n    })\n    .AddFormatterMappings()\n    .AddJsonFormatters()\n    .AddXmlSerializerFormatters()\n    .AddMsgPackFormatters()\n    ;\n}\n```\n\n### Custom configuration\n\nDefault configuration can be changed by providing callback to `AddMessagePack` method.\n\nAvailable settings:\n* `MediaTypes` - allows to specify additional media handled by MessagePack formatters. Default is `application/x-msgpack`.\n* `FormatterResolver` - allows to customize serialization, see [MsgPack object serialization](https://github.com/neuecc/MessagePack-CSharp/blob/master/README.md#object-serialization) for details.\n* `FileExtensions` - allows to specify reponse format URL mapping. Default is `msgpack`. See sample project or\n[Microsoft Docs](https://docs.microsoft.com/en-us/aspnet/core/web-api/advanced/formatting?view=aspnetcore-2.2#response-format-url-mappings) for more information.\n* `Compression` - allows to specify LZ4 compression for messages.\n* `UseOldSpecification` - write message using old specification compatibility mode. Reading will support both old and new specifications. See [Message Pack format specification](https://github.com/msgpack/msgpack/blob/master/spec-old.md).\n* `OmitAssemblyVersion` - don't write assembly version and public key token when using typeless formatter.\n* `AllowAssemblyVersionMismatch` - allows assembly version mistmatch when loading types during deserialization.\n\n```\nservices.AddMessagePack(opt =\u003e\n  {\n      opt.MediaTypes.Clear();\n      opt.MediaTypes.Add(\"application/x-messagepack\");\n      opt.FileExtensions.Add(\"messagepack\");\n      opt.FormatterResolver = MessagePack.Resolvers.ContractlessStandardResolverAllowPrivate.Instance;\n  })\n\n```\n\n\n# MediaTypeFormatter for HttpClient\n\n[Microsoft.AspNet.WebApi.Client](https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Client/) package contains adds support for formatting and content negotiation to System.Net.Http.\nIt allows to add custom content serializers by extending `MediaTypeFormatter` class.\n\n\n## Installation\n```\nInstall-Package Alphacloud.MessagePack.HttpFormatter\n```\n\n## Usage\n\n### Sending request\n\nLibrary contains two extension methods `PostAsMsgPackAsync` and `PutAsMsgPackAsync`. To serialize payload `ContractlessStandardResolver` is used, which gives a JSON-like experience.\n\n```\nvar response = await httpClient.PostAsMsgPackAsync(uri, payload, cancellationToken).ConfigureAwait(false);\n\n```\n\n### Reading response\nTo deserialize Msgpack response, formatter must be added to `formatters` collection passed to `ReadAsAsync` extension method.\n\nThis is **recommeded** method as it enables content negotiation.\n```\nvar res = await response.Content.ReadAsAsync\u003cTestModel\u003e(_formatters, CancellationToken.None);\n```\n\nif you are expecting only MsgPack content, use `MsgPackHttpContentExtensions.ReadMsgPackAsAsync()` for `HttpContent`.\n\n# Samples\n\nSample application is located at `src/samples/NetCoreWebApi`.\nSample Postman requests can be found at `src/samples/MessagePack.postman_collection.json`. To post MessagePack content, use `SingleModel.msgpack` located under `src/samples`.\n\n\n# References\n\n* MessagePack format https://msgpack.org/index.html\n* MessagePack-CSharp https://github.com/neuecc/MessagePack-CSharp\n* AddMVC vs AddMvcCore\n  * https://www.stevejgordon.co.uk/aspnetcore-anatomy-deep-dive-index\n  * https://offering.solutions/blog/articles/2017/02/07/difference-between-addmvc-addmvcore/\n* Content negotiation in ASP.NET Core MVC https://code-maze.com/content-negotiation-dotnet-core/\n* Microsoft.AspNet.WebApi.Client https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Client/\n* Source Link - https://github.com/ctaggart/SourceLink\n* Postman https://www.getpostman.com/downloads/\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falphacloud%2Fmessagepack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falphacloud%2Fmessagepack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falphacloud%2Fmessagepack/lists"}