Skip to content

Commit f0d1a5a

Browse files
committed
Edited all patterns, including template
1 parent b275173 commit f0d1a5a

File tree

9 files changed

+292
-354
lines changed

9 files changed

+292
-354
lines changed
Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,30 @@
1-
# Pattern Name
1+
# Pattern name
22

33
Microsoft Graph API Design Pattern
44

5-
 
5+
*Provide a short description of the pattern.*
66

7-
### *Provide a short description of the pattern.*
8-
9-
<BR>
107

118
## Problem
12-
--------
13-
*Describe business context relevant for the pattern.*
14-
*Provide a short description of the problem.*
159

16-
* *
10+
*Describe the business context relevant for the pattern.*
11+
12+
*Provide a short description of the problem.*
1713

1814
## Solution
19-
--------
2015

2116
*Describe how to implement the solution to solve the problem.*
22-
*Describe related patterns.*
23-
24-
* *
2517

26-
## When to Use this Pattern
27-
------------------------
18+
*Describe related patterns.*
2819

29-
*Describe when and why the solution is applicable and when it may not.*
20+
## When to use this pattern
3021

31-
* *
22+
*Describe when and why the solution is applicable and when it might not be.*
3223

33-
## Issues and Considerations
34-
-------------------------
24+
## Issues and considerations
3525

3626
*Describe tradeoffs of the solution.*
3727

38-
39-
* *
40-
4128
## Example
42-
-------
43-
44-
*Provide a short example from real life*
45-
46-
* * 
47-
48-
49-
5029

30+
*Provide a short example from real life.*

graph/patterns/alternate-key.md

Lines changed: 54 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,34 @@
1-
# Alternate Key Pattern
1+
# Alternate key
22

33
Microsoft Graph API Design Pattern
44

5-
_The Alternate Key Pattern provides the ability to query for a single, specific resource identifiable through an alternative set of properties that is not its primary key_
5+
*The alternate key pattern provides the ability to query for a single, specific resource identifiable through an alternative set of properties that is not its primary key.*
66

77
## Problem
88

9-
---
9+
The resources exposed in Microsoft Graph are identified through a primary key, which guarantees uniqueness inside the same resource type. Often though, that same resource can also be uniquely identified by an alternative, more convenient property (or set of properties) that provides a better developer experience.
1010

11-
The resources exposed in Graph are identified through a Primary Key - which guarantees uniqueness inside the same resource type. Often though, that same resource can also be uniquely identified by an alternative, more convenient property (or set of properties) that provides a better developer experience.
11+
Take a look at the `user` resource: while the `id` remains a perfectly valid way to get the resource details, the `mail` address is also a unique property that could be used to identify it.
1212

13-
Take a look at the `user` resource: while the `id` remains a perfectly valid way to get the resource details, the `mail` address is also an unique property that could be used to identify it.
14-
15-
While it is still possible to use the `$filter` query parameter, such as
16-
17-
`GET https://graph.microsoft.com/v1.0/users?$filter=mail eq '[email protected]'`, the returned result is wrapped in an array that needs to be unpacked.
13+
While it is still possible to use the `$filter` query parameter, such as `GET https://graph.microsoft.com/v1.0/users?$filter=mail eq '[email protected]'`, the returned result is wrapped in an array that needs to be unpacked.
1814

1915
## Solution
2016

21-
---
17+
Resource addressing by using an alternative key can be achieved by using the same parentheses-style convention as the canonical key with one difference: single-part alternate keys MUST specify the key property name to unambiguously determine the alternate key.
2218

23-
Resource addressing via an alternative key can be achieved using the same parentheses-style convention as for the canonical key, with one difference: single-part alternate keys MUST specify the key property name to unambiguously determine the alternate key. (Note: this is a hypothetical sample)
19+
The following is a hypothetical sample:
2420

25-
https://graph.microsoft.com/v1.0/users(0) - Retrieves the employee with ID = 0
26-
https://graph.microsoft.com/v1.0/users(email='[email protected]') Retrieves the employee with the email matching `[email protected]`
21+
https://graph.microsoft.com/v1.0/users(0) - Retrieves the employee with ID = 0.
2722

28-
## When to Use this Pattern
23+
https://graph.microsoft.com/v1.0/users(email='[email protected]') Retrieves the employee with the email matching `[email protected]`.
2924

30-
---
25+
## When to use this pattern
3126

32-
This pattern works and makes sense when the alternate key is good enough to identify a single resource and provides an useful alternative to the client.
27+
This pattern works and makes sense when the alternate key is good enough to identify a single resource and provides a useful alternative to the client.
3328

3429
## Example
3530

36-
---
37-
38-
The same user identified via the alternate key SSN, the canonical (primary) key ID using the non-canonical long form with specified key property name, and the canonical short form without key property name
31+
The same user is identified via the alternate key SSN, the canonical (primary) key ID using the non-canonical long form with a specified key property name, and the canonical short form without a key property name.
3932

4033
Declare `mail` and `ssn` as alternate keys on an entity:
4134

@@ -75,59 +68,59 @@ Declare `mail` and `ssn` as alternate keys on an entity:
7568

7669
1. Get a specific resource through `$filter`:
7770

78-
```http
79-
GET https://graph.microsoft.com/v1.0/users/?$filter=ssn eq '123-45-6789'
80-
```
71+
```http
72+
GET https://graph.microsoft.com/v1.0/users/?$filter=ssn eq '123-45-6789'
73+
```
74+
75+
```json
76+
{
77+
"value": [
78+
{
79+
"givenName": "Bob",
80+
"jobTitle": "Retail Manager",
81+
"mail": "[email protected]",
82+
"mobilePhone": "+1 425 555 0109",
83+
"officeLocation": "18/2111",
84+
"preferredLanguage": "en-US",
85+
"surname": "Vance",
86+
"userPrincipalName": "[email protected]",
87+
"id": "1a89ade6-9f59-4fea-a139-23f84e3aef66"
88+
}
89+
]
90+
}
91+
```
92+
93+
2. Get a specific resource either through its primary key or through the two alternate keys:
94+
95+
```http
96+
GET https://graph.microsoft.com/v1.0/users/1a89ade6-9f59-4fea-a139-23f84e3aef66
97+
GET https://graph.microsoft.com/v1.0/users(ssn='123-45-6789')
98+
GET https://graph.microsoft.com/v1.0/users(mail='[email protected]')
99+
```
81100
82-
```json
83-
{
84-
"value": [
101+
> **Note:** When requesting a resource through its primary key, you might prefer to use `key-as-segment` (as shown earlier). Also, `key-as-segment` does not work for alternate keys.
102+
103+
All three yield the same response:
104+
105+
```json
85106
{
86107
"givenName": "Bob",
87108
"jobTitle": "Retail Manager",
88109
"mail": "[email protected]",
89110
"mobilePhone": "+1 425 555 0109",
90111
"officeLocation": "18/2111",
91112
"preferredLanguage": "en-US",
113+
"ssn": "123-45-6789",
92114
"surname": "Vance",
93115
"userPrincipalName": "[email protected]",
94116
"id": "1a89ade6-9f59-4fea-a139-23f84e3aef66"
95117
}
96-
]
97-
}
98-
```
99-
100-
2. Get a specific resource either through its primary key, or through the two alternate keys:
101-
102-
```http
103-
GET https://graph.microsoft.com/v1.0/users/1a89ade6-9f59-4fea-a139-23f84e3aef66
104-
GET https://graph.microsoft.com/v1.0/users(ssn='123-45-6789')
105-
GET https://graph.microsoft.com/v1.0/users(mail='[email protected]')
106-
```
118+
```
107119
108-
**NOTE:** When requesting a resource through its primary key you might want to prefer to use key-as-segment (as shown above). Also, the key-as-segment does not work for alternate keys.
109-
110-
All of the 3 will yield the sare response:
111-
112-
```json
113-
{
114-
"givenName": "Bob",
115-
"jobTitle": "Retail Manager",
116-
"mail": "[email protected]",
117-
"mobilePhone": "+1 425 555 0109",
118-
"officeLocation": "18/2111",
119-
"preferredLanguage": "en-US",
120-
"ssn": "123-45-6789",
121-
"surname": "Vance",
122-
"userPrincipalName": "[email protected]",
123-
"id": "1a89ade6-9f59-4fea-a139-23f84e3aef66"
124-
}
125-
```
126-
127-
3. Requesting a resource for an unsupported alternate key property
120+
3. Request a resource for an unsupported alternate key property:
128121
129-
```http
130-
GET https://graph.microsoft.com/v1.0/users(name='Bob')
131-
132-
400 Bad Request
133-
```
122+
```http
123+
GET https://graph.microsoft.com/v1.0/users(name='Bob')
124+
125+
400 Bad Request
126+
```

graph/patterns/change-tracking.md

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,55 @@
1-
# Change Tracking
1+
# Change tracking
22

33
Microsoft Graph API Design Pattern
44

55
*The change tracking pattern provides the ability to keep API consumers in sync with changes in Microsoft Graph without having to continuously poll the API.*
66

77
## Problem
8-
---------
98

10-
API consumers require an efficient way to keep data in sync with Microsoft Graph, and the API design should be optimized to avoid polling as it is costly for consumers and producers alike as well as wouldn't guarantee data integrity.
9+
API consumers require an efficient way to keep data in sync with Microsoft Graph. The API design should be optimized to avoid polling because it is costly for consumers and producers alike and wouldn't guarantee data integrity.
1110

1211
## Solution
13-
--------
1412

1513
API designers can enable the change tracking (delta) capability on entity collections by declaring a delta function for API consumers to use to track changes in that collection.
1614

17-
This new endpoint can be used to sync API consumers. This is achieved through returning a delta link with a watermark. Once the API consumer needs to refresh the data it uses the last provided delta link to catch up on new changes since their last request. Delta guarantees integrity of data through the watermark, regardless of service partitions and other obscure aspects for clients.
15+
This new endpoint can be used to sync API consumers. This is achieved through returning a delta link with a watermark. After the API consumer refreshes the data, it uses the last provided delta link to catch up on new changes since their last request. Delta guarantees integrity of data through the watermark, regardless of service partitions and other obscure aspects for clients.
1816

19-
> Note: although this capability is similar to the [OData $delta feed](https://docs.oasis-open.org/odata/odata-json-format/v4.0/errata02/os/odata-json-format-v4.0-errata02-os-complete.html#_Toc403940644) capability, it is a different construct. Microsoft Graph APIs MUST provide change tracking through the delta function and MUST NOT implement the OData $delta feed when providing change tracking capabilities to ensure the uniformity of the API experience.
17+
> **Note:** Although this capability is similar to the [OData $delta feed](https://docs.oasis-open.org/odata/odata-json-format/v4.0/errata02/os/odata-json-format-v4.0-errata02-os-complete.html#_Toc403940644) capability, it is a different construct. Microsoft Graph APIs MUST provide change tracking through the delta function and MUST NOT implement the OData $delta feed when providing change tracking capabilities to ensure the uniformity of the API experience.
2018
21-
## Issues and Considerations
22-
-------------------------
19+
## When to use this pattern
2320

24-
Implementer MUST implement a watermark storage system in case of active watermarks. Passive watermarks are watermarks that can be retrieved from the context (e.g. timestamp), active watermarks represent information required to track the sync state which cannot be retrieved from the context (e.g. cursor from data store, partition affinity marker, partition id, generated unique sync identifier...)
21+
Before using the change tracking pattern in your API definition, make sure that your scenario fits the following criteria:
2522

26-
Implementer MUST implement soft deletion for entities in the backend storage system. The soft deletion will provide useful information to the client to appropriately reflect deletions.
23+
- API consumers want to sync the data.
24+
- API consumers don't want to be immediately notified of changes (see the change notifications pattern for this scenario).
25+
- API consumers are not looking for a "one-time" export or back-up mechanism.
2726

28-
When an entity is soft deleted, the delta function MUST return the id of the deleted entity as well as a `@removed` annotation with the `reason` field.
29-
- The reason MUST be set to `changed` if the entity can be restored. `"@removed": {"reason": "changed"}`.
30-
- The reason MUST be set to `deleted` if the entity cannot be restored. `"@removed": {"reason": "deleted"}`.
27+
### Alternatives
3128

32-
When a link to an entity is deleted, or when the linked entity is deleted, or when a link to an entity is added, implementer MUST return a `property@delta` annotation. e.g. considering the entity Group has a navigation property named members of type Collection(user):
29+
- Change notifications pattern (TODO add link when described)
30+
- Backup pattern (TODO)
3331

34-
- When a user is added to the group `"members@delta": [{ "@odata.type": "#microsoft.graph.user", "id of the added user"}]`
35-
- When a user is removed from the group, or the target user is deleted `"members@delta": [{"@removed": {"reason": "deleted"}, "id of the deleted or removed user"}]`
32+
## Issues and considerations
3633

37-
> Note: the delta function also provides support for $filter and $select to allow the API consumer to narrow down the number of entities and properties retrieved as well as the number of changes that are tracked. Additionally the delta function can also support $top to allow the API consumer to sync smaller sets of changes as well as $expand to allow the API consumer to sync related data. Expand across workloads is not supported today however.
34+
The implementer MUST implement a watermark storage system in case of active watermarks. Passive watermarks are watermarks that can be retrieved from the context (for example, timestamp). Active watermarks represent information required to track the sync state, which cannot be retrieved from the context (such as a cursor from data store, partition affinity marker, partition ID, or generated unique sync identifier).
3835

39-
## When to Use this Pattern
40-
------------------------
36+
The implementer MUST implement soft deletion for entities in the backend storage system. The soft deletion provides useful information to the client to appropriately reflect deletions.
4137

42-
Before using the change tracking pattern in your API definition, make sure your scenario fits the following criteria:
38+
When an entity is soft deleted, the delta function MUST return the ID of the deleted entity as well as a `@removed` annotation with the `reason` field.
4339

44-
- API consumers want to sync the data.
45-
- API consumers don't want to be immediately notified of changes. (see change notifications pattern for this scenario).
46-
- API consumers are not looking for a "one-time" export or back-up mechanism.
40+
- The reason MUST be set to `changed` if the entity can be restored: `"@removed": {"reason": "changed"}`
41+
- The reason MUST be set to `deleted` if the entity cannot be restored: `"@removed": {"reason": "deleted"}`
4742

48-
### Alternatives
43+
When a link to an entity is deleted, when the linked entity is deleted, or when a link to an entity is added, the implementer MUST return a `property@delta` annotation. For example, considering the entity Group has a navigation property named members of type Collection(user):
4944

50-
- Change notifications pattern (TODO add link when described)
51-
- Backup pattern (TODO)
45+
- When a user is added to the group `"members@delta": [{ "@odata.type": "#microsoft.graph.user", "id of the added user"}]`
46+
- When a user is removed from the group, or the target user is deleted from `"members@delta": [{"@removed": {"reason": "deleted"}, "id of the deleted or removed user"}]`
47+
48+
> **Note:** The delta function also provides support for `$filter` and `$select` to allow the API consumer to narrow down the number of entities and properties retrieved as well as the number of changes that are tracked. Additionally, the delta function can support `$top` to allow the API consumer to sync smaller sets of changes as well as `$expand` to allow the API consumer to sync related data. However, expanding across workloads is not currently supported.
5249
5350
## Examples
54-
-------
5551

56-
### Getting changes for the users entity set
52+
### Get changes for the users entity set
5753

5854
```HTTP
5955
GET https://graph.microsoft.com/v1.0/users/delta
@@ -94,7 +90,7 @@ GET https://graph.microsoft.com/v1.0/users/delta
9490
}
9591
```
9692

97-
> Note: the response contains an `@odata.deltaLink` instance annotation with the watermark only when all the changes are enumerated. If more changes need to be enumerated, the response instead contains an `@odata.nextLink` instance annotation the application can request right away to get the next page.
93+
> **Note:** The response contains an `@odata.deltaLink` instance annotation with the watermark only when all the changes are enumerated. If more changes need to be enumerated, the response instead contains an `@odata.nextLink` instance annotation that the application can request right away to get the next page.
9894
9995
### CSDL example
10096

graph/patterns/dictionary-client-guidance.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Dictionary types
22

3-
Note: this document is to be moved into a central client guidance document in the future.
3+
> **Note:** This document will be moved into a central client guidance document in the future.
44
5-
The client guidance is a collection of additional information provided to SDK implementers and client applications. This information is meant to help understand how various guidelines and concept translate in their world and clarify a few unknowns. You should always read the corresponding guideline first to get a context understanding.
5+
*The client guidance is a collection of additional information provided to SDK implementers and client applications. This information is meant to help understand how various guidelines and concepts translate in their world and clarify a few unknowns. Always read the corresponding guideline first to get a contextual understanding.*
66

7-
[Read the guideline](./index.md).
7+
[Read the guidelines](https://github.com/microsoft/api-guidelines/blob/vNext/Guidelines.md).
88

99
## OpenAPI example
1010

11-
The following json-schema/OpenAPI example defines a dictionary of which values will by of type **RoleSettings**.
11+
The following json-schema/OpenAPI example defines a dictionary of which values are of type **RoleSettings**.
1212

13-
In **components** in **schemas**:
13+
In **components** in **schemas**:
1414

1515
```json
1616
{
@@ -38,13 +38,13 @@ In **components** in **schemas**:
3838
}
3939
```
4040

41-
## SDK Support
41+
## SDK support
4242

43-
SDKs need to provide support for dictionary types so SDK consumers get a delightful development experience. Examples are provided below for different languages. Other aspects need to be taken into considerations:
43+
SDKs need to provide support for dictionary types so that SDK consumers get a delightful development experience. Examples are provided for different languages. Other aspects need to be taken into consideration:
4444

45-
- Dictionaries support OData annotations (values prefixed with **@OData**), such annotations should not be inserted directly in the dictionary but rather in the additional properties manager.
46-
- Dictionary types can inherit another dictionary type, this inheritance must be respected.
47-
- Dictionary values can be of union types, if the target language doesn't support union types, a wrapper type should be generated as backward compatible solution with properties for each type of the union.
45+
- Dictionaries support OData annotations (values prefixed with **@OData**); such annotations should not be inserted directly in the dictionary but rather in the additional properties manager.
46+
- Dictionary types can inherit another dictionary type; this inheritance must be respected.
47+
- Dictionary values can be of union types; if the target language doesn't support union types, a wrapper type should be generated as a backward compatible solution with properties for each type of the union.
4848

4949
### Dotnet
5050

@@ -74,6 +74,6 @@ or
7474

7575
## Request builder generation annotation
7676

77-
By default SDKs are not required to contain a set of request builders to run CRUD requests on entries in the dictionary. The dictionary will be updated as a whole by consumers by sending requests to the parent entity.
77+
By default, SDKs are not required to contain a set of request builders to run CRUD requests on entries in the dictionary. The dictionary is updated as a whole by consumers by sending requests to the parent entity.
7878

7979
If a **SupportedHttpMethod** annotation is specified for the dictionary type, request builders should be generated to allow consumers to automatically update the entries.

0 commit comments

Comments
 (0)