Quantcast
Channel: Web Api – no dogma blog
Viewing all articles
Browse latest Browse all 26

Web API 2 Controller with multiple get methods

$
0
0

I have two other posts on multiple GET methods, one for ASP.NET 5 Web Api, and another for Web Api 2.

It seems that every version of Web API changes how it handles default routes or route prefixes or whatever the next name will be.

I’ve written previously on how to handle multiple get methods in Asp.Net 5 Web API.

It’s a little different in Web Api 2.

using System.Web.Http;

namespace WebApiMultipleGets.Controllers
{
    [RoutePrefix("api/values")]
    public class ValuesController : ApiController
    {
        public string Get()
        {
            return "simple get";
        }

        [Route("geta")]
        public string GetA()
        {
            return "A";
        }

        [Route("getb")]
        public string GetB()
        {
            return "B";
        }

        [Route("getc")]
        public string GetC()
        {
            return "C";
        }

        [Route("getd")]
        public string GetD()
        {
            return "D";
        }
    }
}


Viewing all articles
Browse latest Browse all 26

Trending Articles