Data is the bedrock of any API. Nate explains how to use Entity Framework Core to build light classes that represent data models.
- One great thing about entity framework is that you can use simple classes to represent your database models or entities. These are sometimes called POCOs or plain old CLR objects. We can create a model that will represent a room in the database. I'll create this in the models folder and call it room entity. This entity model will have three properties. It'll have a guid ID. It'll have a string name and it'll have an int rate.
The rate property will store the price of the room in the database. We're storing the rate here as an integer because storing decimals with the correct precision can be a little tricky. Instead we'll just cheat and store the prices in cents and remember to divide by 100 later. Next we'll create the corresponding resource that the API will actually return to the client itself. I'll add another class, this time just called room. And this class will inherit from resource because this is the restful resource that will be returned to the client.
This resource class will simply have a name and a decimal rate. This room resource doesn't contain an ID property because the href will function as a unique restful ID. Splitting up the entity model and the resource model in this way gives us the flexibility to control exactly what will be returned to the client. We now have everything we need to pull a room out of the database and return it from a controller. Before we wire everything up in a controller, let's see the database with some test data, so we actually have a room to return.
- 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 Applicationswith 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.