Skip to content

Commit 1ec3c4e

Browse files
committed
feat(301): add undelete pattern, replace soft-delete
The current soft-delete pattern has the undesirable side effect of adding special-casing and additional query parameters to the standard methods, as well as possibly impacting their behavior. Introducing undelete, which is a resource oriented solution that achieves much of the same user journeys: - Restoring resources after being deleted. - Listing / getting deleted resources to figure out what is restorable. fixes #111.
1 parent 322db5c commit 1ec3c4e

4 files changed

Lines changed: 100 additions & 1 deletion

File tree

aep/general/0164/aep.md.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Soft delete
22

3+
**NOTE: this pattern is now deprecated, and is no longer valid. Please use
4+
[undelete](/undelete) instead.**
5+
36
There are several reasons why a client could desire soft delete and undelete
47
functionality, but one over-arching reason stands out: recovery from mistakes.
58
A service that supports undelete makes it possible for users to recover

aep/general/0164/aep.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
id: 164
3-
state: approved
3+
state: deprecated
44
slug: soft-delete
55
created: 2020-10-06
66
placement:

aep/general/0301/aep.md.j2

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Undelete
2+
3+
There are several reasons why a client could desire undelete functionality, but
4+
one over-arching reason stands out: recovery from mistakes. A service that
5+
supports undelete makes it possible for users to recover resources that were
6+
deleted by accident.
7+
8+
## Guidance
9+
10+
Services **may** support the ability to "undelete", to allow for situations
11+
where users mistakenly delete resources and need the ability to recover.
12+
13+
These resources **must** be stored in a separate sibling collection, prefixed
14+
with `deleted-`. (e.g. `deleted-books`). Resources deleted will remain in this
15+
sibling collection until they expire, or until they are undeleted into the
16+
original collection.
17+
18+
Resources that support soft delete **should** have an `expire_time` field on
19+
the deleted version of the resource, as described in AEP-148.
20+
21+
### Sibling collection
22+
23+
To implement the undelete pattern, a sibling collection,
24+
`deleted-{resource_plural}`, **should** be created where all undeletable
25+
resources can be listed and retrieved, as well as undeleted via the `Undelete`
26+
custom method:
27+
28+
EXAMPLE TO BE ADDED
29+
30+
### Undelete
31+
32+
The `Undelete` custom method **should** be available. A successful call to this
33+
method will:
34+
35+
1. remove the resource from the deleted collection.
36+
2. restore the resource back into the original collection.
37+
38+
{% tab proto %}
39+
40+
TODO: add undelete proto sample
41+
42+
- The HTTP method **must** be `POST`.
43+
- The `body` clause **must** be `"*"`.
44+
- The response message **must** be the resource itself. There is no
45+
`UndeleteDeletedBookResponse`.
46+
- The response **should** include the fully-populated resource.
47+
- A `path` field **must** be included in the request message; it **should** be
48+
called `path`.
49+
- The field **should** be [annotated as required][aep-203].
50+
- The field **should** identify the [resource type][aep-4] that it
51+
references.
52+
- The comment for the field **should** document the resource pattern.
53+
- The request message **must not** contain any other required fields, and
54+
**should not** contain other optional fields except those described in this
55+
or another AEP.
56+
57+
{% tab oas %}
58+
59+
TODO: add undelete oas sample
60+
61+
- The HTTP method **must** be `POST`.
62+
- The response message **must** be the resource itself.
63+
- The response **should** include the fully-populated resource.
64+
- The operation **must not** require any other fields, and **should not**
65+
contain other optional query parameters except those described in this or
66+
another AEP.
67+
68+
{% endtabs %}
69+
70+
### Long-running undelete
71+
72+
Some resources take longer to undelete a resource than is reasonable for a
73+
regular API request. In this situation, the API **should** follow the
74+
long-running request pattern AEP-151.
75+
76+
### Errors
77+
78+
If the user calling `Undelete` has proper permission, but the requested
79+
resource is not deleted, the service **must** error with `409 Conflict`.
80+
81+
For additional guiance, see [errors](/errors).
82+
83+
## Further reading
84+
85+
- For the `Delete` standard method, see AEP-135.
86+
- For long-running operations, see AEP-151.
87+
- For resource freshness validation (`etag`), see AEP-154.
88+
- For change validation (`validate_only`), see AEP-163.

aep/general/0301/aep.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
id: 301
3+
state: approved
4+
slug: undelete
5+
created: 2020-10-06
6+
placement:
7+
category: design-patterns
8+
order: 95

0 commit comments

Comments
 (0)