Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating Web API Hello World
Message
From
18/12/2016 09:03:26
 
General information
Forum:
ASP.NET
Category:
Visual Studio
Miscellaneous
Thread ID:
01645380
Message ID:
01645475
Views:
34
Just add a regular class and paste the code into it. If you are adding yours from scratch then all that matters is that the class be derived from ApiController as in the example....
HTH

>I wanted to add your example of the ApiController to the project that VS created (for learning/testing). When I right-mouse click on the Controllers folder I don't see how I can add it. The item Controllers is grayed. What am I not understanding?
>
>>> Like, do I need to know how the routing works, in MVC?
>>
>>Not if you use attribute routing. It's one (probably the main) advantage. e.g.:
    [RoutePrefix("api/chat")]
>>    public class MyChatController : ApiController
>>    {
>>        [HttpGet]
>>        [Route("/greeting")]
>>        public HttpResponseMessage SayHello ()
>>        {
>>            return Request.CreateResponse(HttpStatusCode.OK, "Hello World");
>>        }
>>        [HttpGet]
>>        [Route("/farewell")]
>>        public HttpResponseMessage GoodBye()
>>        {
>>            return Request.CreateResponse(HttpStatusCode.OK, "See you later");
>>        }
>>    }
So the routing is controlled solely by the RoutePrefix and Route attributes rather than the method names: e.g:
http://mysite.com/api/chat/greeting
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform