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"; } } }
Pingback: Web API 2 Controller with multiple GET methods – part 2 | no dogma blog
Nice ..this helped me lot. Here is my code with multiple parameters which may help some one :
[RoutePrefix(“api/File”)]
public class FileController : ApiController
{
[Route(“getfile”)]
public HttpResponseMessage GetFile(string docid, string sourceurl)
{
//do
return “string”;
}
[HttpGet]
[Route(“savefile”)]
public string SaveFile(string docid, string sourceurl, string destinationurl)
{
//do
return “string”;
}
Calling like this
http://localhost:12345/api/file/getfile?docid=1234&sourceurl=http://pcm.com/testpcm/
and
http://localhost:57916/api/file/savefile?docid=2&sourceurl=http://testing.com&destinationurl=http://destination.com
No need to change anything in routeconfig/webapiconfig.
-PURNA
Great It clear a lot -:)
Thanks for letting me know.
Thanks a lot
You are welcome.
Thank you Sir!!
You are welcome, sir!
Pingback: ASP.NET 5 Web Api Controller with multiple get methods | no dogma blog