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: README.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
-
># NOTICE TO READERS
2
-
>
3
-
>## Guidance for Azure service teams
4
-
> Azure service teams should use companion documents, [Azure REST API Guidelines](./azure/Guidelines.md) and [Considerations for Service Design](./azure/ConsiderationsForServiceDesign.md), when building or modifying their services. These documents provide a refined set of guidance targeted specifically for Azure services. For more information please refer to the [README](./azure/README.md) in the Azure folder.
5
-
>
6
-
> ## Guidance for Microsoft Graph service teams
7
-
>Microsoft Graph service teams should reference the companion document, [Graph REST API Guidelines](./graph/GuidelinesGraph.md) when building or modifying their services.
8
-
>
9
-
> In the process of building many of Microsoft's highest scale services, the Microsoft Graph team found the Microsoft API guidelines tremendously useful as a baseline. However, there are several areas where we need to provide more clarity on how developers should describe their APIs. The companion document, [Graph REST API Guidelines](./graph/GuidelinesGraph.md) is a set of amendments and clarifications for Microsoft Graph that act as further reading. Recognizing that two documents is a lot for a new API designer to absorb, our plan is to follow the approach Azure have taken and roll out guidelines for Microsoft Graph into a single consolidated document.
1
+
# NOTICE TO READERS
2
+
3
+
## Guidance for Azure service teams
4
+
Azure service teams should use companion documents, [Azure REST API Guidelines](./azure/Guidelines.md) and [Considerations for Service Design](./azure/ConsiderationsForServiceDesign.md), when building or modifying their services. These documents provide a refined set of guidance targeted specifically for Azure services. For more information please refer to the [README](./azure/README.md) in the Azure folder.
5
+
6
+
## Guidance for Microsoft Graph service teams
7
+
Microsoft Graph service teams should reference the companion document, [Graph REST API Guidelines](./graph/GuidelinesGraph.md) when building or modifying their services.
8
+
9
+
In the process of building many of Microsoft's highest scale services, the Microsoft Graph team found the Microsoft API guidelines tremendously useful as a baseline. However, there are several areas where we need to provide more clarity on how developers should describe their APIs. The companion document, [Graph REST API Guidelines](./graph/GuidelinesGraph.md) is a set of amendments and clarifications for Microsoft Graph that act as further reading. Recognizing that two documents is a lot for a new API designer to absorb, our plan is to follow the approach Azure have taken and roll out guidelines for Microsoft Graph into a single consolidated document.
Copy file name to clipboardExpand all lines: azure/ConsiderationsForServiceDesign.md
+1-6Lines changed: 1 addition & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -180,12 +180,7 @@ This header is targeted at developers or operation professionals, and it is inte
180
180
A major inhibitor to adoption and usage is when an API behaves in an unexpected way. Often, these are subtle design decisions that seem benign at the time, but end up introducing significant downstream friction for developers.
181
181
182
182
One common area of friction for developers is _polymorphism_ -- where a value may have any of several types or structures.
183
-
Polymorphism can be beneficial in certain cases, e.g. as a way to express inheritance, but also creates friction
184
-
because it requires the value to be introspected before being processed and cannot be represented in a natural/useful way in many type-safe languages.
185
-
186
-
:ballot_box_with_check:**YOU SHOULD** avoid polymorphism, especially in the response. An endpoint **YOU SHOULD** work with a single type to avoid problems during SDK creation.
187
-
188
-
:ballot_box_with_check:**YOU SHOULD** return a homogeneous collection (single type). Do not return heterogeneous collections unless there is a really good reason to do so. If you feel heterogeneous collections are required, discuss the requirement with an API reviewer prior to implementation.
183
+
Polymorphism can be beneficial in certain cases, e.g. as a way to express inheritance, but also creates friction because it requires the value to be introspected before being processed and cannot be represented in a natural/useful way in many nominally typed languages. The use of a discriminator field (`kind`) simplifies the introspection, but developers frequently end up having to explicitly cast the response to the appropriate type in order to use it.
189
184
190
185
Collections are another common area of friction for developers. It is important to define collections in a consistent manner within your service and across services of the platform. In particular, features such as pagination, filtering, and sorting, when supported, should follow common API patterns. See [Collections](./Guidelines.md#collections) for specific guidance.
Copy file name to clipboardExpand all lines: azure/Guidelines.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -430,13 +430,14 @@ This indicates to client libraries and customers that values of the enumeration
430
430
431
431
#### Polymorphic types
432
432
433
-
<ahref="#json-avoid-polymorphism"name="json-avoid-polymorphism">:warning:</a> **YOU SHOULD NOT** use polymorphic JSON types because they greatly complicate the customer code due to runtime dynamic casts and the introduction of new types in the future.
433
+
Polymorphism types in REST APIs refers to the possibility to use the same property of a request or response to have similar but different shapes. This is commonly expressed as a `oneOf`in JsonSchema or OpenAPI. In order to simplify how to determine which specific type a given request or response payload corresponds to, Azure requires the use of an explicit discriminator field.
434
434
435
-
If you can't avoid them, then follow the guideline below.
435
+
Note: Polymorphic types can make your service more difficult for nominally typed languages to consume. See the corresponding section in the [Considerations for service design](./ConsiderationsForServiceDesign.md#avoid-surprises) for more information.
436
436
437
437
<ahref="#json-use-discriminator-for-polymorphism"name="json-use-discriminator-for-polymorphism">:white_check_mark:</a> **DO** define a discriminator field indicating the kind of the resource and include any kind-specific fields in the body.
438
438
439
439
Below is an example of JSON for a Rectangle and Circle with a discriminator field named `kind`:
-[API contract and non-backward compatible changes](#api-contract-and-non-backward-compatible-changes)
19
18
-[Versioning and deprecation](#versioning-and-deprecation)
20
19
-[Recommended API design patterns](#recommended-api-design-patterns)
21
20
-[References](#references)
22
21
23
-
##
24
-
25
-
#### History
26
-
27
-
| Date | Notes |
28
-
|-------------|-----------------------------|
29
-
| 2022-Jun-14 | Edit pass for formatting, links |
30
-
| 2021-Sep-28 | Using summary and patterns style |
31
-
| 2020-Oct-04 | Initial version in Wiki |
32
22
33
23
## Introduction
34
24
35
-
When building a digital ecosystem API, usability becomes a business priority. The success of your ecosystem depends on APIs that are easy to discover, simple to use, fit for purpose, and consistent across your products.
25
+
When building a digital ecosystem API usability becomes a business priority. The success of your ecosystem depends on APIs that are easy to discover, simple to use, fit for purpose, and consistent across your products.
36
26
37
27
This document offers guidance that Microsoft Graph API producer teams MUST follow to
38
28
ensure that Microsoft Graph has a consistent and easy-to-use API surface. A new API design should meet the following goals:
@@ -125,6 +115,7 @@ Following is a short summary of the most often used conventions.
125
115
|:ballot_box_with_check:**SHOULD** prefix property names for properties concerning a different entity. | - **Right:** siteWebUrl on driveItem or userId on auditActor <BR> - **Wrong:** webUrl on contact when it's the companyWebUrl |
126
116
|:ballot_box_with_check:**SHOULD** prefix Boolean properties with `is`, unless this leads to awkward or unnatural sounding names for Boolean properties. | - **Right:** isEnabled or isResourceAccount <BR>- **Wrong:** enabled or allowResourceAccount <BR> - **Right:** allowNewTimeProposals or allowInvitesFrom (subjectively more natural than the following examples) <BR> - **Wrong:** isNewTimeProposalsAllowed or isInvitesFromAllowed (subjectively more awkward that the preceding examples) |
127
117
|:no_entry:**MUST NOT** use collection, response, or request suffixes. | - **Right:** addresses <BR> - **Wrong:** addressCollection |
@@ -220,6 +211,8 @@ The three most often used patterns in Microsoft Graph today are type hierarchy,
220
211
221
212
-**[Flat bag of properties](./patterns/flat-bag.md)** is represented by one entity type with all the potential properties plus an additional property to distinguish the variants, often called type. The type property describes the variant and also defines properties that are required or meaningful for the variant given by the type property.
222
213
214
+
-**[Enums](./patterns/enums.md)** represent a subset of the nominal type they rely on, and are especially useful in cases where certain properties have predefined, limited options.
215
+
223
216
The following table shows a summary of the main qualities for each pattern and can help you select a pattern fit for your use case.
224
217
225
218
| API qualities\patterns | Properties and behavior described in metadata | Supports combinations of properties and behaviors | Simple query construction |
@@ -249,6 +242,31 @@ Following are a few pros and cons to decide which pattern to use:
249
242
> **Note:**
250
243
> As can be seen in a few of the pros and cons, one of the important aspects discussed here is that the API design goes beyond the syntactical aspects of the API. Therefore, it is important to plan ahead how the API evolves, lay the foundation, and allow users to form a good understanding of the semantics of the API. **Changing the semantics is always a breaking change.** The different modeling patterns differ in how they express syntax and semantics and how they allow the API to evolve without breaking compatibility. For more information, see [API contract and non-backward compatible changes](#api-contract-and-non-backward-compatible-changes) later in this article.
251
244
245
+
#### Nullable properties
246
+
247
+
The facet and flat bag approaches often require nullable properties, so it is important to still use non-nullable properties where appropriate.
248
+
Since inheritance can often remove the use of nullable properties completely, it is also important to know when nullable properties are necessary.
249
+
See [Nullable properties](./nullable.md) for more details.
250
+
251
+
### Query support
252
+
253
+
Microsoft Graph APIs should support basic query options in conformance with OData specifications and [Microsoft REST API Guidelines for error condition responses](https://github.com/microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses).
|:heavy_check_mark:**MUST** support `$select on resource` to enable properties projection. |
258
+
|:ballot_box_with_check:**SHOULD** support `/entityTypeCollection/{id}?$expand=navProp1` option for navigation properties of entities. |
259
+
|:ballot_box_with_check:**SHOULD** support `$filter` with `eq` and `ne` operations on properties of entity collections. |
260
+
|:heavy_check_mark:**MUST** support [server-driven pagination](https://github.com/microsoft/api-guidelines/blob/vNext/Guidelines.md#981-server-driven-paging) of collections using a [nextLink](http://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_ControlInformationnextLinkodatanextL). |
261
+
|:ballot_box_with_check:**SHOULD** support [client-driven pagination](https://github.com/microsoft/api-guidelines/blob/vNext/Guidelines.md#982-client-driven-paging) of collections using `$top` and `$skip` (or `$skipToken`). |
262
+
|:ballot_box_with_check:**SHOULD** support `$count` for collections. |
263
+
|:ballot_box_with_check:**SHOULD** support sorting with `$orderby` both ascending and descending on properties of the entities. |
264
+
265
+
The query options part of an OData URL can be quite long, potentially exceeding the maximum length of URLs supported by components involved in transmitting or processing the request. One way to avoid this is to use the POST verb instead of GET with the `$query` segment, and pass the query options part of the URL in the request body as described in the chapter
Another way to avoid this is to use JSON batch as described in the [Microsoft Graph batching documentation](https://docs.microsoft.com/graph/json-batching#bypassing-url-length-limitations-with-batching).
269
+
252
270
### Behavior modeling
253
271
254
272
The HTTP operations dictate how your API behaves. The URL of an API, along with its request/response bodies, establishes the overall contract that developers have with your service. As an API provider, how you manage the overall request/response pattern should be one of the first implementation decisions you make.
@@ -257,7 +275,8 @@ If possible, APIs SHOULD use resource-based designs with standard HTTP methods r
|:heavy_check_mark:**MUST** use POST to create new entities in insertable entity sets or collections.<BR>This approach requires the server to produce system generated identities. |
278
+
|:heavy_check_mark:**MUST** use POST to create new entities in insertable entity sets or collections.<BR>This approach requires the service to produce a system-generated key, or for a caller to provide a key in the request payload. |
279
+
|:ballot_box_with_check:**SHOULD** additionally use PATCH to create new entities in insertable entity sets or collections.<BR>This [Upsert](./patterns/upsert.md) approach requires the caller to provide a key in the request URL. |
261
280
|:heavy_check_mark:**MUST** use PATCH to edit updatable resources. |
262
281
|:heavy_check_mark:**MUST** use DELETE to delete deletable resources. |
263
282
|:heavy_check_mark:**MUST** use GET for listing and reading resources. |
@@ -268,6 +287,7 @@ Operation resources must have a binding parameter that matches the type of the b
268
287
269
288
For a complete list of standard HTTP operations, see the [Microsoft REST API Guidelines error condition responses](https://github.com/microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses).
270
289
290
+
271
291
### Error handling
272
292
273
293
Microsoft REST API Guidelines provide guidelines that Microsoft Graph APIs should follow when returning error condition responses. You can improve API traceability and consistency by using the recommended Microsoft Graph error model and the Microsoft Graph utilities library to provide a standard implementation for your service:
@@ -390,6 +410,8 @@ The guidelines in previous sections are intentionally brief and provide a jump s
390
410
|[Navigation properties](./patterns/navigation-property.md)| Model resource relationships |
391
411
|[Operations](./patterns/operations.md)| Model complex business operations |
392
412
|[Type hierarchy](./patterns/subtypes.md)| Model `is-a` relationships using subtypes. |
413
+
|[Upsert](./patterns/upsert.md)| Idempotent operation to create or update a resource using a client-provided key. |
414
+
|[Viewpoint](./patterns/viewpoint.md)| Model user specific properties for a shared resource. |
0 commit comments