Reputation: 3885
I'm writing a webhook in asp.net core mvc where the caller posts some json. But the Content-Type is set to application/vnd.myget.webhooks.v1+json
. I just want to have this content type map to the JsonInputFormatter
.
I did this, but wondering if there is a better way:
services.AddMvc( mvcConfig =>
{
var formatter = new JsonInputFormatter();
formatter.SupportedMediaTypes.Add(
new MediaTypeHeaderValue("application/vnd.myget.webhooks.v1+json") );
mvcConfig.InputFormatters.Add( formatter );
});
Upvotes: 7
Views: 2480
Reputation: 10291
You can modify the default InputFormatter
in ConfigureServices
services.Configure<MvcOptions>(options => {
options.InputFormatters.OfType<JsonInputFormatter>().First().SupportedMediaTypes.Add(
new MediaTypeHeaderValue("application/vnd.myget.webhooks.v1+json")
);
});
...perhaps a slight improvement
Upvotes: 6