Skip to content

Commit 512bd54

Browse files
author
Dan Kershaw [MSFT]
committed
Addressed feedback from OlgaPodo
1 parent 9ff0e15 commit 512bd54

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

graph/patterns/upsert.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
Microsoft Graph API Design Pattern
44

5-
*The `UPSERT` pattern is a non-destructive idempotent operation using a client-provided key, that ensures that system resources can be deployed in a reliable, repeatable, and controlled way, typically used in Infrastructure as Code (IaC) scenarios.*
5+
*The `Upsert` pattern is a non-destructive idempotent operation using a client-provided key, that ensures that system resources can be deployed in a reliable, repeatable, and controlled way, typically used in Infrastructure as Code (IaC) scenarios.*
66

77
## Problem
88

9-
Infrastructure as code (IaC) defines system resources and topologies in a descriptive manner that allows teams to manage those resources as they would code.
9+
Infrastructure as code (IaC) defines system resources and topologies in a declarative manner that allows teams to manage those resources as they would code.
1010
Practicing IaC helps teams deploy system resources in a reliable, repeatable, and controlled way.
1111
IaC also helps automate deployment and reduces the risk of human error, especially for complex large environments.
1212
Customers want to adopt IaC practices for many of the resources managed through Microsoft Graph.
@@ -19,20 +19,20 @@ Additionally, IaC code scripts or templates usually employ client-provided names
1919

2020
## Solution
2121

22-
The solution is to use an `UPSERT` pattern, to solve for the non-idempotent creation and client-provided naming problems.
22+
The solution is to use an `Upsert` pattern, to solve for the non-idempotent creation and client-provided naming problems.
2323

24-
* For IaC scenarios, resources must use `UPSERT` semantics with an [alternate key](./alternate-key.md):
24+
* For IaC scenarios, resources must use `Upsert` semantics with an [alternate key](./alternate-key.md):
2525
* Use `PATCH` with a client-provided alternate key.
2626
* For a non-existent resource (specified by the alternate key) the service must handle this as a "create". As part of creation, the service must still generate the primary key value.
2727
* For an existing resource (specified by the alternate key) the service must handle this as an "update.
2828
* Any new alternate key, used for IaC scenarios, should be called `uniqueName`, if there isn't already an existing property that could be used as an alternate key.
2929
* NOTE: the service must also support `GET` using the alternate key pattern.
3030
* For consistent CRUD Microsoft Graph behaviors, all resources, **including** resources used in IaC scenarios, should use `POST` and a service-generated primary key, per existing guidelines, and support `GET`, `PATCH` and `DELETE` using the primary key.
31-
* If a service does not support `UPSERT`, then a `PATCH` call against a non-existent resource must result in an HTTP "409 conflict" error.
31+
* If a service does not support `Upsert`, then a `PATCH` call against a non-existent resource must result in an HTTP "409 conflict" error.
3232

33-
This solution allows for existing resources that follow Microsoft Graph conventions for CRUD operations to add `UPSERT` without impacting existing apps or functionality.
33+
This solution allows for existing resources that follow Microsoft Graph conventions for CRUD operations to add `Upsert` without impacting existing apps or functionality.
3434

35-
Ideally, all new entity types should support an `UPSERT` mechanism, especially if the resource is likely be used in IaC scenarios.
35+
Ideally, all new entity types should support an `Upsert` mechanism, especially where they support control-plane APIs, or are used in admin style or IaC scenarios.
3636

3737
## When to use this pattern
3838

@@ -42,10 +42,10 @@ This pattern should be adopted for resources that are managed through infrastruc
4242

4343
* The addition of this new pattern (with alternate key) does not represent a breaking change.
4444
However, some API producers may have concerns about accidental usages of this new pattern unwittingly creating many new resources when the intent was an update.
45-
As a result, API producers can use the `Prefer: idempotent` to require clients to opt-in to the UPSERT behavior.
45+
As a result, API producers can use the `Prefer: idempotent` to require clients to opt-in to the Upsert behavior.
4646
* The client-provided alternate key must be immutable after being set. If its value is null then it should be settable as a way to backfill existing resources for use in IaC scenarios.
4747
* API producers could use `PUT` operations to create or update, but generally this approach is not recommended due to the destructive nature of `PUT`'s replace semantics.
48-
* API producers could to use `UPSERT` with a primary (client-provided) key and this may be appropriate for some scenarios. However, the recommendation is for resources to support creation using `POST` and a service-generated primary key, for consistency reasons.
48+
* API producers could use `Upsert` with a primary (client-provided) key and this may be appropriate for some scenarios. However, the recommendation is for resources to support creation using `POST` and a service-generated primary key, for consistency reasons.
4949
* API producers may annotate entity sets, singletons and collections to indicate that entities can be "upserted". The example below shows this annotation for the `groups` entity set.
5050

5151
```xml
@@ -94,6 +94,7 @@ Create a new group, with a `uniqueName` of "Group157". In this case, this group
9494

9595
```http
9696
PATCH /groups(uniqueName='Group157')
97+
Prefer: idempotent; return=representation
9798
```
9899

99100
```json
@@ -107,6 +108,7 @@ Response:
107108

108109
```http
109110
201 created
111+
Preference-Applied: idempotent; return=representation
110112
```
111113

112114
```json
@@ -124,6 +126,7 @@ Create a new group, with a `uniqueName` of "Group157", exactly like before. Exce
124126

125127
```http
126128
PATCH /groups(uniqueName='Group157')
129+
Prefer: idempotent; return=representation
127130
```
128131

129132
```json
@@ -137,6 +140,7 @@ Response:
137140

138141
```http
139142
200 ok
143+
Preference-Applied: idempotent; return=representation
140144
```
141145

142146
```json
@@ -153,10 +157,11 @@ Notice how this operation is idempotent in nature, rather than returning a 409 c
153157
### Upsert not supported
154158

155159
Create a new group, with a `uniqueName` of "Group157". In this case, this group does not exist and additionally
156-
the service does not `UPSERT` for groups.
160+
the service does not `Upsert` for groups.
157161

158162
```http
159163
PATCH /groups(uniqueName='Group157')
164+
Prefer: idempotent; return=representation
160165
```
161166

162167
```json

0 commit comments

Comments
 (0)