The basic Web API template includes a number of good defaults for ASP.NET Core MVC, but Nate demonstrates a few tweaks that will save time down the road.
- [Instructor] Before we start writing code, there are a few configuration changes we can make. The launchsettings.json file contains settings that are passed on to IAS Express. We'll come back to this file when we set up HTTPS. For now, set launchBrowser to false. We'll be using an HTTP client to interact with the API, so having Visual Studio launch a browser every time we'd run the project is kind of annoying. Next, I'm going to open up the startup.cs file. This file contains three important methods.
The constructor reads a file called appsettings.json, which contains application-specific configuration. We don't need to change anything here yet. The configure services method is where you can add any services you need to the ASP.NET Core dependency injection system. The template is already adding the services needed for MVC, which is the middleware that does routing and controller logic for ASP.NET Core. Finally, the configure method sets up the application pipeline.
This is where you add the middleware you want to respond to incoming requests. A common pattern for configuring services is to pass some configuration options in the configuration services method. In our case, we want to change one setting. By default, the routing middleware in ASP.NET Core will use Pascal Case for rendering controller names. I prefer lowercase URLs, so I'll pass this option to the routing service. The routing service method takes an options parameter, and I can say options dot LowercaseUrls equals true.
It's important to note that the order of calls in the configure services method doesn't matter, but the order of calls in the configure method does matter because the configure method represents the ordered application pipeline that will respond to incoming requests. So that's it for now. We'll come back and add more services later. But next, let's build a controller.
- REST vs. RPC
- Using HTTP methods (aka verbs)
- Returning JSON
- Creating a new API project
- Building a root controller
- Routing to controllers with templates
- Requiring HTTPS for security
- Creating resources and data models
- Returning data and resources from a controller
- Representing links (HREFs)
- Representing collections
- Sorting and searching collections
- Creating forms
- Caching and compression
- Authentication and authorization for RESTful APIs
Skill Level Intermediate
Deploying ASP.NET Core Applications (2017)with Nate Barbettini57m 57s Intermediate
1. REST API Concepts
2. Building a Basic API
3. Securing the API
4. Representing Resources
5. Representing Links
6. Representing Collections
7. Sorting Collections
8. Searching Collections
9. Forms and Modifying Data
10. Caching and Compression
11. Authentication and Authorization
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.