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/dictionary/index.md
+44-13Lines changed: 44 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,40 @@
1
-
# Dictionary types
1
+
# Dictionary
2
+
3
+
Microsoft Graph API Design Pattern
4
+
5
+
*The Dictionary type provides the ability to create a set of primitives or objects, of the same type, where the API consumer can define a name for each value in the set.*
6
+
7
+
## Problem
8
+
--------
9
+
10
+
The API design requires a resource to include an unknown quantity of similar data elements that need to be named using values provided by the API consumer.
11
+
12
+
## Solution
13
+
--------
14
+
15
+
API designers use a JSON object to represent a dictionary in a `application/json`response payload. When describing the model in CSDL, a new complex type can be created that derives from `Org.OData.Core.V1.Dictionary` and then use the `Org.OData.Validation.V1.OpenPropertyTypeConstraint`to constrain the type that can be used for the values in the dictionary.
16
+
17
+
Dictionary entries can be added via `POST`, updated via `PATCH`, and they can be removed by setting the entry value to `null`. Multiple dictionaries can be updated at once by using `PATCH` on the dictionary property.
18
+
19
+
## Issues and Considerations
20
+
-------------------------
2
21
3
22
Dictionaries, sometimes called maps, are a collection of name-value pairs. They allow dynamic data sets to be accessed in a systematic manner and are a good compromise between a strictly defined ahead of time structure with all its named properties and between a loosely defined dynamic object (i.e. OData OpenTypes).
4
23
24
+
As dictionary entries are removed via setting the value to null, this means that dictionaries can only support values that are non-nullable.
25
+
26
+
OpenQuestions:
27
+
- Can/should PUT be supported on the dictionary property and/or the entry value
28
+
- What does OData say about being able to POST to a structured property? Will OData Web API allow that?
29
+
- Must an implementer support PATCH at both the dictionary level and the entry level?
Before using a dictionary type in your API definition make sure your scenario fits the following criteria:
12
40
@@ -20,7 +48,10 @@ Before using a dictionary type in your API definition make sure your scenario fi
20
48
-[Open types](https://docs.microsoft.com/en-us/aspnet/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/use-open-types-in-odata-v4) when your data is not a collection in nature.
21
49
-[Complex types](https://docs.microsoft.com/en-us/odata/webapi/complextypewithnavigationproperty) when the set of data values are known.
22
50
23
-
## JSON payload example
51
+
## Examples
52
+
-------
53
+
54
+
### JSON payload example
24
55
25
56
The following example illustrates the resulting JSON for a property of dictionary type. The parent object has been ommitted for brievety.
26
57
@@ -38,11 +69,11 @@ The following example illustrates the resulting JSON for a property of dictionar
38
69
}
39
70
```
40
71
41
-
## HTTP calls examples
72
+
###HTTP calls examples
42
73
43
74
In this set of examples we're modeling a **roles** property of dictionary type on the user entity which is exposed by the users entity set.
44
75
45
-
### Getting an entry from the dictionary
76
+
####Getting an entry from the dictionary
46
77
47
78
```HTTP
48
79
GET https://graph.microsoft.com/v1.0/users/10/roles/author
@@ -56,7 +87,7 @@ Reponse:
56
87
}
57
88
```
58
89
59
-
### Getting the dictionary
90
+
####Getting the dictionary
60
91
61
92
```HTTP
62
93
GET https://graph.microsoft.com/v1.0/users/10/roles
@@ -78,7 +109,7 @@ Reponse:
78
109
}
79
110
```
80
111
81
-
### Getting the entity with the dictionary
112
+
####Getting the entity with the dictionary
82
113
83
114
```HTTP
84
115
GET https://graph.microsoft.com/v1.0/users/10
@@ -104,7 +135,7 @@ Reponse:
104
135
}
105
136
```
106
137
107
-
### Creating an entry in the dictionary
138
+
####Creating an entry in the dictionary
108
139
109
140
```HTTP
110
141
POST https://graph.microsoft.com/v1.0/users/10/roles/author
@@ -114,7 +145,7 @@ POST https://graph.microsoft.com/v1.0/users/10/roles/author
The following example defines a complex type **roleSettings** as well as a dictionary of which the key will be a string and the value a **roleSettings**.
159
190
@@ -182,6 +213,6 @@ The following example defines a complex type **roleSettings** as well as a dicti
0 commit comments