liveBook · Manning

PATCH

As explained in .NET in Action, Second Edition

PATCH is an HTTP method conventionally used to apply a partial update to a resource.

PATCH applies a partial update to an existing resource. Unlike PUT, which conventionally replaces an object, PATCH lets a caller change only selected fields. section 5.5

A practical PATCH handler:

  • Accepts the resource identifier, an update command with nullable fields, and a cancellation token. section 5.5
  • Loads the existing entity and returns 404 when the identifier is not found. section 5.5
  • Assigns each supplied non-null field, saves changes asynchronously, and returns 204 No Content. section 5.5

Updating a book

A BookUpdateCommand containing only Description changes the description while leaving Title unchanged. Returning Ok(book) with 200 is an alternative when the updated object should be returned. section 5.5

How .NET in Action, Second Edition covers it

How deep it goes
Works through lookup, conditional field assignment, persistence, status codes, and an alternative response, but not PATCH document formats.
Examples
Demonstrates partially updating a Book through nullable Title and Description command fields.
What it assumes
Assumes familiarity with HTTP APIs, C# controllers, asynchronous methods, and Entity Framework Core entity persistence.
What you can do after
Apply partial updates through a C# controller while handling missing entities and asynchronous database persistence.
How it connects
Connects PATCH with PUT, HTTP status codes, C# records, cancellation tokens, and Entity Framework Core.

Also explained in

Compare how 4 books explain PATCH →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET in Action, Second Edition. The section links point to the parts of the book it draws on.