Learn how to create an abstraction that represents the base resource type for the API. Nate explains how to leverage the built-in serialization in ASP.NET Core to keep the model clean and simple.
- [Instructor] Restful APIs are all about returning and manipulating resources. Let's add a base class for all the resource models we'll need to return from the API. I'll create this in the Models folder. And I'm going to create a class called simply Resource. I'm going to make this class abstract because we want other classes to inherit from this base class. And the only property that the resource class will have for now is a string property called href. I can change how this property is serialized by adding a JSON property attribute which comes from JSON.net.
In this case I want to add an order property and set the order to a negative two. In JSON.net this means that this property will be at the very top of all serialized responses. Machines don't really care about this, but it's a nice touch for humans that are reading the API. Because of this href property that we added, every resource return from the API will include an href that contains the absolute URI of the resource itself. This self referential link will take the place of an ID property and is a restful way of expressing which resource or document the client is currently viewing or manipulating.
Now we can create classes that extend this base class. The simplest case is a resource that contains some static information about the hotel. I'm going to create a new model called Hotel Information, or Hotel Info, and have it inherit from resource. Now I'll add a few more properties to this. The hotel can have a title, a tagline or slogan, an email address, a website address, and also an address or a location.
I'll create a new class to hold that. An address will just have a street, and a city, and a country. Next we'll use the configuration pattern in ASP.NET Core to populate this class with some data.
- 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
Building Web APIs with ASP.NET Core (2016)with Chris Woodruff1h 7m 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.