data-api-builder icon indicating copy to clipboard operation
data-api-builder copied to clipboard

[Bug]: REST PATCH does not work with Identity keys

Open JerryNixon opened this issue 8 months ago • 0 comments

What?

Endpoints that support Upsert currently require the key in the route. But when the entity uses identity or auto-generated keys, this route becomes impossible to fulfill.

PATCH

PATCH /api/Entity/Id/{Id}

The URL requires a key, which new records with auto-generated keys don't have.

PUT

PUT /api/Entity/Id/{Id}

The URL requires a key, which new records with auto-generated keys don't have.

Fix

Introduce alternative routes that do not require a key in the URL:

  • PATCH /entity — handles partial updates and upserts without needing an Id in the path
  • PUT /entity — handles full replacements or upserts for records with auto-generated keys

ASP.NET supports multiple routes per controller, so this dual-route setup is valid. For backward compatibility, we keep the original routes, but add these new keyless ones to support common identity scenarios. The internal engine logic should be reusable—only the API surface changes.

Other

To keep Swagger/OpenAPI output clean, we might omit the legacy routes from documentation. Otherwise, two PATCH or PUT operations per entity will appear, even though only one is typically the intended usage pattern.

JerryNixon avatar Apr 22 '25 03:04 JerryNixon