This course will be retired on July 14, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Let's configure a default API route so Web API will know how to map incoming requests to controller action methods.
Follow Along
To follow along committing your changes to this course, you'll need to fork the aspnet-fitness-frog-spa repo. Then you can clone, commit, and push your changes to your fork like this:
git clone <your-fork>
cd aspnet-fitness-frog-spa
git checkout tags/v2.2 -b defining-a-default-api-route
Comparing Web API and MVC Default Routes
The default routes for Web API and MVC are similar, but also significantly different in two ways:
- The Web API default route typically includes the literal path segment
api
. This helps to prevent collisions between Web API and MVC routes. - The Web API doesn't define a route parameter for the
action
. Instead, the request's HTTP method is used to determine which controller action method should be called.
For reference, here's a typical ASP.NET Web API default route:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional });
And a typical MVC default route:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Entries",
action = "Index", id = UrlParameter.Optional } );
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up