ITsolutionWizard
asked on
MVC WebApi Response Type
Hi Experts, have a copy of basic route inside of MVC webapi. I want to add a parameter eg.
response type: xml, json, text and etc. The idea is to define the response type so it is easier for us to organize when they are consumed.
How to tell each mvc controller. And I do not want to Get like api.com/1?responsetype=xml.
I prefer to use in http post so it will be more secure.
Please show me the changes in codes.
Thanks,
response type: xml, json, text and etc. The idea is to define the response type so it is easier for us to organize when they are consumed.
How to tell each mvc controller. And I do not want to Get like api.com/1?responsetype=xml.
I prefer to use in http post so it will be more secure.
Please show me the changes in codes.
Thanks,
[HttpPost]
[Route("api/Invoice/CreateInvoiceDetail")]
public int CreateInvoiceDetail(Domain.Invoice i)
{
#region mapping
#endregion
_invoiceNumber = _masterInvoice.CreateInvoiceDetail(_invoice);
return _invoiceNumber;
}
namespace WebAPI
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER