You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: graph/GuidelinesGraph.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -216,7 +216,7 @@ The three most often used patterns in Microsoft Graph today are type hierarchy,
216
216
217
217
-**[Facets](./patterns/facets.md)** are represented by a single entity type with common properties and one facet property (of complex type) per variant. The facet properties only have a value when the object represents that variant.
218
218
219
-
-**[Flat bag of properties]/(./patterns/flat-bag.md)** is represented by one entity type with all the potential properties plus an additional property to distinguish the variants, often called type. The type property describes the variant and also defines properties that are required or meaningful for the variant given by the type property.
219
+
-**[Flat bag of properties](./patterns/flat-bag.md)** is represented by one entity type with all the potential properties plus an additional property to distinguish the variants, often called type. The type property describes the variant and also defines properties that are required or meaningful for the variant given by the type property.
220
220
221
221
The following table shows a summary of the main qualities for each pattern and can help you select a pattern fit for your use case.
222
222
@@ -234,7 +234,7 @@ Following are a few pros and cons to decide which pattern to use:
234
234
235
235
- Introducing new cases in **hierarchy** is relatively isolated (which is why it is so familiar to OOP) and is considered backwards compatible (at least syntactically).
236
236
237
-
- Introducing new cases/variants in **[facets](./patterns/facets.md)** is straightforward. You need to be careful because it can introduce situations where previously only one of the facets was non-null and now all the old ones are null. This is not unlike adding new subtypes in the **hierarchy** pattern or adding a new type value in the **flat** pattern.
237
+
- Introducing new cases/variants in **[facets](./patterns/facets.md)** is straightforward. You need to be careful because it can introduce situations where previously only one of the facets was non-null and now all the old ones are null. This is not unlike adding new subtypes in the **hierarchy** pattern or adding a new type value in the **[flat bag](./patterns/flat-bag.md)** pattern.
238
238
239
239
-**hierarchy** and **facets** (to a slightly lesser degree) are well-suited for strongly typed client programming languages, whereas **flat bag** is more familiar to developers of less strongly typed languages.
240
240
@@ -380,8 +380,8 @@ The guidelines in previous sections are intentionally brief and provide a jump s
380
380
|[Dictionary](./patterns/dictionary.md)| Clients can provide an unknown quantity of data elements of the same type. |
381
381
|[Evolvable enums](./patterns/evolvable-enums.md)| Extend enumerated types without breaking changes. |
382
382
|[Facets](./patterns/facets.md)| Model parent-child relationships. |
383
-
|[Flat bag](./patterns/flat-bag.md)| Model variants of the same type. |
384
-
|[Long running operations](./patterns/longRunningOperations.md)| Model operations where processing a client request takes a long time. |
383
+
|[Flat bag](./patterns/flat-bag.md)| Model variants of the same type.|
384
+
|[Long running operations](./patterns/longRunningOperations.md)| Model operations where processing a client request takes a long time. |
385
385
|[Modeling subsets](./patterns/subsets.md)| Model collection subsets for All, None, Included, or Excluded criteria. |
386
386
|[Namespace](./patterns/namespace.md)| Organize resource definitions into a logical set. |
387
387
|[Type hierarchy](./patterns/subtypes.md)| Model `is-a` relationships using subtypes. |
Copy file name to clipboardExpand all lines: graph/patterns/facets.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ In this solution, a child variant is identified by the presence of one or more f
19
19
20
20
The facet pattern is useful when there is a number of variants and they are not mutually exclusive. It also makes it syntactically easier to query resources by using OData $filter expression because it doesn't require casting.
21
21
22
-
You can consider related patterns such as [Type hierarchy](./subtypes.md) and Flat bag of properties.
22
+
You can consider related patterns such as [type hierarchy](./subtypes.md) and [flat bag of properties](./flat-bag.md).
Copy file name to clipboardExpand all lines: graph/patterns/flat-bag.md
+8-10Lines changed: 8 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,33 +1,31 @@
1
-
# Flat Bag of properties Pattern
1
+
# Flat bag of properties
2
2
3
3
Microsoft Graph API Design Pattern
4
4
5
5
*A known pattern in Microsoft Graph is to model multiple variants of a common concept as a single entity type with all potential properties plus an additional property to distinguish the variants.*
6
6
7
-
8
7
## Problem
9
8
10
-
API designers need to model a small and limited number of variants of a common concept with a concise list of non-overlapping properties and consistent behavior across variant. The designer also wants to simplify query construction.
9
+
API designers need to model a small and limited number of variants of a common concept with a concise list of non-overlapping properties and consistent behavior across variants. The designer also wants to simplify query construction.
11
10
12
11
## Solution
13
12
14
-
The API designer creates one entity type with all the potential properties plus an additional property to distinguish the variants, often called `variantType`. For each value of `variantType`some properties are meaningful and others are ignored.
13
+
The API designer creates one entity type with all the potential properties plus an additional property to distinguish the variants, often called `variantType`. For each value of `variantType`, some properties are meaningful and others are ignored.
15
14
16
15
## When to use this pattern
17
16
18
-
The Flat bag pattern is useful when there is a small number of variants with similar behavior and variants are queried for mostly read-only operations.
19
-
The pattern also makes it syntactically easier to query resources by using OData $filter expression because it doesn't require casting.
17
+
The flat bag pattern is useful when there is a small number of variants with similar behavior, and variants are queried for mostly read-only operations. The pattern also makes it syntactically easier to query resources by using the OData `$filter` expression because it doesn't require casting.
20
18
21
19
## Issues and considerations
22
20
23
-
In general the Flat bag pattern is the least recommended modeling choice because it is weakly typed and it is difficult to semantically verify targeted resource modifications. But there are circumstances when query simplicity and limited number of properties may overweight considerations of more strongly typed approach.
24
-
The pattern is not recommended for large number of variants and properties because the payload becomes sparsely populated.
21
+
In general, the flat bag pattern is the least recommended modeling choice because it is weakly typed, and it is difficult to semantically verify targeted resource modifications. However, there are circumstances when query simplicity and a limited number of properties might overweight considerations of a more strongly typed approach.
22
+
The pattern is not recommended for a large number of variants and properties because the payload becomes sparsely populated.
25
23
26
-
You can consider related patterns such as Type hierarchy and Flat bag of properties.
24
+
You can consider related patterns such as [type hierarchy](./subtypes.md) and [facets](./facets.md).
27
25
28
26
## Example
29
27
30
-
A good example for Flat bag implementation is the recurrencePattern type on [recurrencePattern](https://docs.microsoft.com/en-us/graph/api/resources/recurrencepattern?view=graph-rest-1.0).
28
+
A good example for flat bag implementation is the recurrencePattern type on [recurrencePattern](https://docs.microsoft.com/graph/api/resources/recurrencepattern).
31
29
32
30
The recurrencePattern has six variants expressed as six different values of the `type` property (for example: daily, weekly, ...). The key here is that for each of these values, some properties are meaningful and others are ignored (for example: `daysOfWeek` is relevant when `type` is `weekly` but not when it is `daily`).
Copy file name to clipboardExpand all lines: graph/patterns/long-running-operations.md
+39-45Lines changed: 39 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,17 @@
2
2
3
3
Microsoft Graph API Design Pattern
4
4
5
-
__*The long running operations (LRO) pattern provides the ability to model operations where processing a client request takes a long time, but the client isn't blocked and can do some other work until operation completion.*__
5
+
*The long running operations (LRO) pattern provides the ability to model operations where processing a client request takes a long time, but the client isn't blocked and can do some other work until operation completion.*
6
6
7
7
## Problem
8
8
9
9
The API design requires modeling operations on resources, which takes a long time
10
10
to complete so that API clients don't need to wait and can continue doing other
11
11
work while waiting for the final operation results. The client should be able to
12
12
monitor the progress of the operation and have an ability to cancel it if
13
-
needed. The API needs to provide a mechanism to track the work
13
+
needed.
14
+
15
+
The API needs to provide a mechanism to track the work
14
16
being done in the background. The mechanism needs to be expressed in the same
15
17
web style as other interactive APIs. It also needs to support checking on the status and/or
16
18
being notified asynchronously of the results.
@@ -24,18 +26,15 @@ operation.
24
26
There are two flavors of this solution:
25
27
26
28
- The returned resource is the targeted resource and includes the status of
27
-
the operation. This pattern is often called RELO (resource-based
28
-
long running operation).
29
+
the operation. This pattern is often called RELO (resource-based long running operation).
29
30
30
31
<!-- markdownlint-disable MD033 -->
31
32
<palign="center">
32
33
<imgsrc="RELO.gif"alt="The status monitor LRO flow"/>
33
34
</p>
34
35
<!-- markdownlint-enable MD033 -->
35
36
36
-
- The returned resource is a new API resource called 'Stepwise Operation' and
37
-
is created to track the status. This LRO solution is similar to the concept
38
-
of Promises or Futures in other programming languages.
37
+
- The returned resource is a new API resource called *stepwise operation* and is created to track the status. This LRO solution is similar to the concept of Promises or Futures in other programming languages.
39
38
40
39
<!-- markdownlint-disable MD033 -->
41
40
<palign="center">
@@ -47,32 +46,28 @@ The RELO pattern is the preferred pattern for long running operations and should
47
46
used wherever possible. The pattern avoids complexity, and consistent resource
48
47
presentation makes things simpler for our users and tooling chain.
49
48
50
-
In general, Microsoft Graph API guidelines for LRO follow [Microsoft REST API
49
+
In general, Microsoft Graph API guidelines for long running operations follow [Microsoft REST API
There are some deviations from the base guidelines where Microsoft Graph API standards require that you do one of the following:
54
53
55
-
- For RELO pattern you should return the Location header that indicates the location of the resource.
54
+
- For the RELO pattern, you should return the Location header that indicates the location of the resource.
56
55
- The API response says the targeted resource is being created by returning a 201 status code and the resource URI is provided in the Location header, but the response indicates that the request is not completed by including "Provisioning" status.
57
56
58
-
- For LRO pattern you should return the Location header that indicates the location of a new stepwise operation resource.
57
+
- For the LRO pattern, you should return the Location header that indicates the location of a new stepwise operation resource.
59
58
- The API response says the operation resource is being created at the URL provided in the Location header and indicates that the request is not completed by including a 202 status code.
60
-
- Microsoft Graph doesn’t allow tenantwide operation resources therefore stepwise operations is often modeled as a navigation property on the target resource.
59
+
- Microsoft Graph doesn’t allow tenant-wide operation resources; therefore, stepwise operations are often modeled as a navigation property on the target resource.
61
60
62
61
## When to use this pattern
63
62
64
-
Any API call that is expected to take longer than 1 second in the 99th percentile should use the long running operations pattern.
63
+
Any API call that is expected to take longer than one second in the 99th percentile should use the long running operations pattern.
65
64
66
-
How do you select which flavor of LRO pattern to use? An API designer can follow these
67
-
heuristics:
65
+
How do you select which flavor of LRO pattern to use? An API designer can follow these heuristics:
68
66
69
-
1. If a service can create a resource with a minimal latency and continue
70
-
updating its status according to the well-defined and stable state
71
-
transition model until completion, then the RELO model is the best choice.
67
+
1. If a service can create a resource with a minimal latency and continue updating its status according to the well-defined and stable state transition model until completion, then the RELO model is the best choice.
72
68
73
-
2.Otherwise, a service should follow the Stepwise Operation pattern.
69
+
2. Otherwise, a service should follow the stepwise operation pattern.
74
70
75
-
76
71
## Issues and considerations
77
72
78
73
- One or more API consumers MUST be able to monitor and operate on the same resource at the same time.
@@ -82,32 +77,28 @@ heuristics:
82
77
resource is no longer active. Clients MAY issue a GET on some resource to
83
78
determine the state of a long running operation.
84
79
85
-
-The long running operations pattern SHOULD work for clients looking to "fire and forget"
80
+
- The long running operations pattern SHOULD work for clients looking to "fire and forget"
86
81
and for clients looking to actively monitor and act upon results.
87
82
88
-
- The long running operations pattern might be supplemented by the [change notification
89
-
pattern](change-notification.md).
83
+
- The long running operations pattern might be supplemented by the [change notification pattern](./change-notification.md).
90
84
91
-
-Cancellation of a long running operation does not explicitly mean a rollback. On a per API-defined case, it
92
-
might mean a rollback, or compensation, or completion, or partial completion,
85
+
- Cancellation of a long running operation does not explicitly mean a rollback. On a per API-defined case, it
86
+
might mean a rollback or compensation or completion or partial completion,
93
87
etc. Following a canceled operation, the API should return a consistent state that allows
94
88
continued service.
95
89
96
-
-A recommended minimum retention time for a stepwise operation is 24 hours.
90
+
- A recommended minimum retention time for a stepwise operation is 24 hours.
97
91
Operations SHOULD transition to "tombstone" for an additional period of time
98
92
prior to being purged from the system.
99
93
100
-
- Services that provides a new operation resource MUST support GET semantics on the operation.
101
-
- Services that returns a new operation MUST always return an LRO (even if the LRO is created in the completed state) that way API consumers don't have to deal with two different shapes of response.
102
-
103
-
94
+
- Services that provide a new operation resource MUST support GET semantics on the operation.
95
+
- Services that return a new operation MUST always return an LRO (even if the LRO is created in the completed state); that way API consumers don't have to deal with two different shapes of response.
104
96
105
97
## Examples
106
98
99
+
### Create a new resource using RELO
107
100
108
-
### Create a new resource using RELO
109
-
110
-
A client wants to provision a new database
101
+
A client wants to provision a new database:
111
102
112
103
```
113
104
POST https://graph.microsoft.com/v1.0/storage/databases/
@@ -119,7 +110,7 @@ POST https://graph.microsoft.com/v1.0/storage/databases/
119
110
120
111
The API responds synchronously that the database has been created and indicates
121
112
that the provisioning operation is not fully completed by including the
122
-
Content-Location header and status property in the response payload.
113
+
Content-Location header and status property in the response payload:
0 commit comments