Web API 2 Controller with multiple get methods
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.
1using System.Web.Http;
2
3namespace WebApiMultipleGets.Controllers
4{
5 [RoutePrefix("api/values")]
6 public class ValuesController : ApiController
7 {
8 public string Get()
9 {
10 return "simple get";
11 }
12
13 [Route("geta")]
14 public string GetA()
15 {
16 return "A";
17 }
18
19 [Route("getb")]
20 public string GetB()
21 {
22 return "B";
23 }
24
25 [Route("getc")]
26 public string GetC()
27 {
28 return "C";
29 }
30
31 [Route("getd")]
32 public string GetD()
33 {
34 return "D";
35 }
36 }
37}