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/patterns/alternate-key.md
+10-12Lines changed: 10 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,10 +2,11 @@
2
2
3
3
Microsoft Graph API Design Pattern
4
4
5
-
*The Alternate Key Pattern provides the ability to query for a single, specific resource identifiable through an alternative attribute (called key) that is not its unique identifier*
5
+
_The Alternate Key Pattern provides the ability to query for a single, specific resource identifiable through an alternative attribute (called key) that is not its unique identifier_
6
6
7
7
## Problem
8
-
--------
8
+
9
+
---
9
10
10
11
All entities in our system are identified by an [UUID (Universally Unique Identifier)](https://en.wikipedia.org/wiki/Universally_unique_identifier) - which guarantees uniqueness. Often though, that same resource can also be uniquely identified by an alternative, more convenient attribute that provides a better developer experience.
11
12
@@ -15,24 +16,26 @@ While it is still possible to use the oData filter, such as
15
16
16
17
`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.
17
18
18
-
19
19
## Solution
20
-
--------
20
+
21
+
---
21
22
22
23
oData offers resource addressing via an alternate key using the same parentheses-style convention as for the canonical key, with one difference: single-part alternate keys MUST specify the key attribute name to unambiguously determine the alternate key.
23
24
24
25
https://graph.microsoft.com/v1.0/users(0) - Retrieves the employee with ID = 0
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; while it does not work if the resultset has more than one element.
31
33
32
-
In such case, we **strongly** advice to throw an exception and encourage the user to use `$filter` rather than returning the first result of the query
34
+
In such case, we **strongly** advice to throw an exception and encourage the user to use `$filter` rather than returning the first result of the query
33
35
34
36
## Example
35
-
-------
37
+
38
+
---
36
39
37
40
The same user identified via the alternate key SSN, the canonical (primary) key ID using the non-canonical long form with specified key attribute name, and the canonical short form without key attribute name
0 commit comments