Skip to content

Commit 252371b

Browse files
committed
markdown format
1 parent 680f5fe commit 252371b

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

graph/patterns/alternate-key.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
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 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_
66

77
## Problem
8-
--------
8+
9+
---
910

1011
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.
1112

@@ -15,24 +16,26 @@ While it is still possible to use the oData filter, such as
1516

1617
`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.
1718

18-
1919
## Solution
20-
--------
20+
21+
---
2122

2223
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.
2324

2425
https://graph.microsoft.com/v1.0/users(0) - Retrieves the employee with ID = 0
2526
https://graph.microsoft.com/v1.0/users(email='[email protected]') Retrieves the employee with the email matching `[email protected]`
2627

2728
## When to Use this Pattern
28-
------------------------
29+
30+
---
2931

3032
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.
3133

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
3335

3436
## Example
35-
-------
37+
38+
---
3639

3740
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
3841

@@ -41,8 +44,3 @@ https://graph.microsoft.com/v1.0/users/1a89ade6-9f59-4fea-a139-23f84e3aef66
4144
https://graph.microsoft.com/v1.0/users(ssn='123-45-6789')
4245

4346
https://graph.microsoft.com/v1.0/users(email='[email protected]')
44-
45-
46-
47-
48-

0 commit comments

Comments
 (0)