Skip to content

Commit 9cac927

Browse files
committed
address other comments
1 parent ffe5f17 commit 9cac927

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

graph/patterns/alternate-key.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ The resources exposed in Graph are identified through a Primary Key - which guar
1212

1313
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.
1414

15-
While it is still possible to use the OData filter, such as
15+
While it is still possible to use the `$filter` query parameter, such as
1616

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+
`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.
1818

1919
## Solution
2020

2121
---
2222

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 property name to unambiguously determine the alternate key. (Note: this is a hypothetical sample)
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)
2424

2525
https://graph.microsoft.com/v1.0/users(0) - Retrieves the employee with ID = 0
2626
https://graph.microsoft.com/v1.0/users(email='[email protected]') Retrieves the employee with the email matching `[email protected]`
@@ -29,7 +29,7 @@ https://graph.microsoft.com/v1.0/users(email='[email protected]') Retrieves the em
2929

3030
---
3131

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; while it does not work if the resultset has more than one element. In such case, the workload SHOULD return `400`
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.
3333

3434
## Example
3535

@@ -40,7 +40,7 @@ The same user identified via the alternate key SSN, the canonical (primary) key
4040
Declare `mail` and `ssn` as alternate keys on an entity:
4141

4242
```xml
43-
<EntityType Name="User">
43+
<EntityType Name="user">
4444
<Key>
4545
<PropertyRef Name="id" />
4646
</Key>
@@ -76,7 +76,7 @@ Declare `mail` and `ssn` as alternate keys on an entity:
7676
1. Get a specific resource through `$filter`:
7777

7878
```http
79-
GET https://graph.microsoft.com/v1.0/users/?$filter=(ssn eq '123-45-6789')
79+
GET https://graph.microsoft.com/v1.0/users/?$filter=ssn eq '123-45-6789'
8080
```
8181

8282
```json
@@ -97,14 +97,16 @@ GET https://graph.microsoft.com/v1.0/users/?$filter=(ssn eq '123-45-6789')
9797
}
9898
```
9999

100-
2. Get a specific resource through its primary key, and then through the two alternate keys:
100+
2. Get a specific resource either through its primary key, or through the two alternate keys:
101101

102102
```http
103103
GET https://graph.microsoft.com/v1.0/users/1a89ade6-9f59-4fea-a139-23f84e3aef66
104104
GET https://graph.microsoft.com/v1.0/users(ssn='123-45-6789')
105105
GET https://graph.microsoft.com/v1.0/users(email='[email protected]')
106106
```
107107

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+
108110
All of the 3 will yield the sare response:
109111

110112
```json

0 commit comments

Comments
 (0)