Tuesday 1 August 2017

Consume and Produces attributes in WebApi DotNet

Produces : It is a filter attribute that specifies the expected System.Type the action will return and the supported response content types.

namespace Microsoft.AspNetCore.Mvc
ProducesAttribute


[HttpGet]
[Produces("text/xml")]
public IEnumerable<string> Get()
{
 return new string[] { "value1", "value2", "Value3" };
}








Consume: It is a filter attribute that specifies the supported request content types.

namespace Microsoft.AspNetCore.Mvc
ConsumesAttribute

[HttpGet]
[Consumes("application/json")]
public IEnumerable<string> Get()
{
 return new string[] { "value1", "value2", "Value3" };
}