Dig deeper into the subtle differences between POST, PUT, and PATCH, and understand when and why to support each method in your API.
- [Narrator] Besides the constraints that the http spec puts on the methods used for full and partial updates, it's worth taking a closer look at the semantics of how updates can be handled in a RESTful API. If we compare the three http methods that can be used for updates, we can see that post can technically be used for both full and partial updates, but only put can do idempotent full updates, and patch is limited to only doing partial updates. According to the http spec, only post returns are response body. Put and patch just return a header like 201 created or 204 no content.
A common pattern of RESTful APIs is to send the created or updated resource to the client in the body of the response, which fits the spec of post but not put or patch. The differences between these methods lead to a couple of common scenarios. One approach is to use all three verbs: post for creating, put for full updates, and patch for partial updates. This approach most closely sticks to the http spec. The downside is that there are a lot of code path to support and not all API's need to distinguish between partial and full updates.
Another approach is to keep it simple. Use post for both creating and updating resources. This means that all updates are treated as partial updates and are not idempotent. This can be simpler for your clients as it doesn't require the client to decide whether to send a partial or full update. Depending on what you need your API to be able to do, you could choose either approach or a combination of the above. In the sample API that we'll build for Landon Hotels in this course, I think approach number two makes the most sense, it's simple and while the API needs to handle partial updates, it doesn't really have a strong need for full updates.
Now that we've thoroughly exhausted the topic of http methods, let's move on to the topic of how to model the responses from our API.
- 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.