Azure / Azure/azure-libraries-for-java
Using ETag for better Create / Update experience
- Dominant language
- Java
- Stars
- 97
- Forks
- 102
- PR merge metrics
- No merged PRs in 30d
Description
Today the `CreateOrUpdate` (PUT) semantic make it difficult to distinguish between Creation and Update of a resource. For example consider user trying to create a new resource group:
```java
ResourceGroup resourceGroup = azure.resourceGroups()
.define("myRG")
.withRegion(Region.US_EAST)
.withTag("aa", "bb")
.create();
```
If the resource group with name "MyRG" already exists user will be expecting an error, but this call still succeeded since we don't have a way to tell server that create it if not exist and fail it already exists.
As per ARM spec, a resource provider can can optionally support ETag specific headers (If-Match, If-None-Match) , if they do then SDK can make use of this header with `CreateOrUpdate` (PUT) calls and provide better experience to the user.
```
define()..create() -> CreateOrUpdate + If-None-Match = "*"
With this, if resource already exits PUT will fail with error code 412
update()..apply() -> CreateOrUpdate + If-Match = "*"
With this, if resource does not exists PUT will fail with error code 412
```
| PUT | Resource does not exist | Resource exists |
| ------------- |:-------------:| -----:|
| If-Match = "" / absent | 201 Created | 200 OK |
| If-Match = "*" | 412 Precondition Failed | 200 OK |
| If-Match = "xyz" | 412 Precondition Failed | 200 OK / 412 Precondition Failed |
| If-None-Match = "*" | 201 Created | 412 Precondition Failed |
Contributor guide
Assessment
This issue has not been assessed yet.