Missing some key nuances of configuring an ASP.NET MVC app to handle RESTful requests.

I've boldly lept into the Ember.js universe, and my Ember advisors are awesome. Here's the rub, I'm locked into an IIS / ASP.NET / MSSQL combo for my web / application / DB due to client requirements. The MSSQL element is a good thing; I know it well. The IIS / ASP.NET elements, however, have been giving me trouble.

I've been using the ASP.NET MVC API template for Ember.js by Xinyang Qiu, Nathan Totten, and Thiago Santos as a starting point. While the API contains some real gems, there are aspects of it that mystify me: A simple POST request hits the API. The following screenshot represents the request, the request headers, and the request payload.

HTTP RequestThe above request results in the following method being called in the API's controller. Additionally, todoListDto, the data-transfer object, is fully populated with the request payload.

Resulting Method Call in ControllerHow is the API pulling this off?

The above method, PostTodoList, is of the type HttpResponseMessage. I suspect that's part of it.
PostTodoList is in the class TodoListController which derives from ApiController. That may be part of it.
Global.asax calls a few methods at startup that I suspect play a key role in the process.

Global.asax CallsI recognize that I'm no ASP.NET MVC expert, far from it. I simply need to know enough of ASP.NET MVC to build a RESTful API for Ember.js. I'm not shy of going to the literature. Just point me to the right literature. I'm also not shy about asking for help. If you can point me to an appropriate online community, I'm happy to go there.
jdanaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dustin HopkinsSenior Web DeveloperCommented:
Hi, great question.
Your suspicions are correct. The call in the global.asax file is configuring the Web Api routing engine.

Web Api, like MVC, prefers convention over configuration. So first when a request is received it is routed to a class in your project that ends with "Controller" and inherits from ApiController. Typically these are placed in a controllers folder, but they don't have to be.

The next convention is the method name. There are a few ways to map methods to http methods. You can use an attribute or start the method name with the method you wish it to respond to. In this case Post of type httpresponsemessage.

Once WebApi finds the controller and the method, it will attempt to create and map the parameters based on the payload.

For further reading on WebApi routing check out this link it goes into more depth and will probably explain things better than I can:
Web Api Routing Overview

Also you may wish to check this out as well:
Getting Started with Web Api 2


Hope this helps,
Dustin
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jdanaAuthor Commented:
Dustin,

Wow. This is a terrific response. Any chance you're free to do some consulting work on this project? My Ember guru, Ian, has been insistent, "Conform with the JSON API." I think he's right, but accomplishing this on the .NET side currently feels daunting. I'm confident you could save me days, if not weeks, of effort. Let me know if you're interested.

John
0
Dustin HopkinsSenior Web DeveloperCommented:
John, I appreciate the offer, however I'm currently swamped with a couple of projects.

Thank you,
Dustin
0
jdanaAuthor Commented:
Steller solution. Thanks again, Dustin.

J
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.