Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

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,


 [HttpPost]
        [Route("api/Invoice/CreateInvoiceDetail")]
        public int CreateInvoiceDetail(Domain.Invoice i)
        {
            #region mapping             
            #endregion
            _invoiceNumber = _masterInvoice.CreateInvoiceDetail(_invoice);
            return _invoiceNumber;
        }

Open in new window


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 }
            );
        }
    }
}

Open in new window

Avatar of ITsolutionWizard
ITsolutionWizard
Flag of United States of America image

ASKER

helps?
ASKER CERTIFIED SOLUTION
Avatar of Jonathan D.
Jonathan D.
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial