Friday, August 28, 2015

web api response plain text formatter

1)Nuget to install WebAPIContrib text formatter, 


initialized it in the Application_Start/WebApiConfig.cs

at end add below line:
  config.Formatters.Add(new PlainTextFormatter());
2) In the controller add "text/plain" parameter.
 public HttpResponseMessage GetPlainText()
{
  return ControllerContext.Request.CreateResponse(HttpStatusCode.OK, "Test data", "text/plain");
}

No comments: