Learn how to create an abstraction that represents the base resource type for the API. Explore 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 gonna 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 JsonProperty attribute which comes from json.NET.
In this case I wanna 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 gonna 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.
- What is RESTful design?
- Building a new API with ASP.NET Core
- Using HTTP methods
- Returning JSON
- Creating RESTful routing with templates
- Securing RESTful APIs with HTTPS
- Representing resources
- Representing links
- Representing collections
- Sorting and searching collections
- Building forms
- Adding caching to an ASP.NET Core API
- Configuring user authentication and authorization
Skill Level Advanced
1. REST API Concepts
2. Build a Basic API
3. Versioning and Errors
4. Secure the API
5. Represent Resources
6. Represent Links
7. Represent Collections
Add pagination7m 37s
8. Sorting Collections
9. Searching Collections
10. Forms and Modifying Data
11. Caching and Compression
12. 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.