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
| 2021-Aug-06 | Updated Azure REST Guidelines per Azure API Stewardship Board. |
9
10
| 2020-Jul-31 | Added service advice for initial versions |
@@ -46,12 +47,12 @@ The Microsoft Azure Cloud platform exposes its APIs through the core building bl
46
47
47
48
### HTTP
48
49
Azure services must adhere to the HTTP specification, [RFC7231](https://tools.ietf.org/html/rfc7231). This section further refines and constrains how service implementors should apply the constructs defined in the HTTP specification. It is therefore, important that you have a firm understanding of the following concepts:
-[HTTP Query Parameters and Header Values](#http-query-parameters-and-header-values)
54
+
55
+
#### Uniform Resource Locators (URLs)
55
56
56
57
A Uniform Resource Locator (URL) is how developers access the resources of your service. Ultimately, URLs are how developers form a cognitive model of your service's resources.
57
58
@@ -88,8 +89,6 @@ Some customer-provided path segment values may be compared case-insensitivity if
88
89
89
90
:heavy_check_mark:**YOU MAY** use these other characters in the URL path but they will likely require %-encoding [[RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986#section-2.1)]: `/ ? # [ ] @ ! $ & ' ( ) * + , ; =`
90
91
91
-
#### Direct Endpoint URLs
92
-
93
92
:heavy_check_mark:**YOU MAY** support a direct endpoint URL for performance/routing:
:white_check_mark:**DO** return URLs in response headers/bodies in a consistent form regardless of the URL used to reach the resource. Either always a UUID for `<tenant>` or always a single verified domain.
The HTTP Request / Response pattern dictates how your API behaves. For example: POST methods that create resources must be idempotent, GET method results may be cached, the If-Modified and ETag headers offer optimistic concurrency. The URL of a service, along with its request/response bodies, establishes the overall contract that developers have with your service. As a service provider, how you manage the overall request / response pattern should be one of the first implementation decisions you make.
112
111
113
112
Cloud applications embrace failure. Therefore, to enable customers to write fault-tolerant applications, _all_ service operations (including POST) **must** be idempotent. Implementing services in an idempotent manner, with an "exactly once" semantic, enables developers to retry requests without the risk of unintended consequences.
114
113
115
-
#### Exactly Once Behavior = Client Retries & Service Idempotency
114
+
#####Exactly Once Behavior = Client Retries & Service Idempotency
116
115
117
116
:white_check_mark:**DO** ensure that _all_ HTTP methods are idempotent.
:white_check_mark:**DO** support caching and optimistic concurrency by honoring the the `If-Match`, `If-None-Match`, if-modified-since, and if-unmodified-since request headers and by returning the ETag and last-modified response headers
148
147
149
-
### HTTP Query Parameters and Header Values
148
+
####HTTP Query Parameters and Header Values
150
149
Because information in the service URL, as well as the request / response, are strings, there must be a predictable, well-defined scheme to convert strings to their corresponding values.
151
150
152
151
:white_check_mark:**DO** validate all query parameter and request header values and fail the operation with `400-Bad Request` if any value fails validation. Return an error response as described in the [Handling Errors](#Handling-errors) section indicating what is wrong so customer can diagnose the issue and fix it themselves.
@@ -160,7 +159,7 @@ Integer | -2<sup>53</sup>+1 to +2<sup>53</sup>-1 (for consistency with JSON li
Date/Time (Query parameter) | YYYY-MM-DDTHH:mm:ss.sssZ (with at most 3 digits of fractional seconds) [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339)
165
164
Byte array | Base-64 encoded, max length
166
165
Array | One of a) a comma-separated list of values (preferred), or b) separate `name=value` parameter instances for each value of the array
:white_check_mark:**DO** compare request header values using case-sensitivity if the header name requires it
198
197
199
-
:white_check_mark:**DO** accept and return date values in headers using the HTTP Date format as defined in [RFC 1123, Section 5.2.14](https://datatracker.ietf.org/doc/html/rfc1123#page-55), e.g. "Sun, 06 Nov 1994 08:49:37 GMT".
198
+
:white_check_mark:**DO** accept date values in headers in HTTP-Date format and return date values in headers in the IMF-fixdate format as defined in [RFC7231, Section 7.1.1.1](https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.1.1), e.g. "Sun, 06 Nov 1994 08:49:37 GMT".
200
199
201
-
Note: RFC 1123 defines the date format as a modification of the date format in [RFC 822, Section 5](https://datatracker.ietf.org/doc/html/rfc822#section-5) to support either a 2 or 4 digit year, and further recommends that a 4 digit year always be used.
200
+
Note: The RFC 7321 IMF-fixdate format is a "fixed-length and single-zone subset" of the RFC 1123 / RFC 5822 format, which means: a) year must be four digits, b) the seconds component of time is required, and c) the timezone must be GMT.
202
201
203
202
:white_check_mark:**DO** create an opaque value that uniquely identifies the request and return this value in the `x-ms-request-id` response header.
204
203
@@ -215,7 +214,7 @@ Your service should include the `x-ms-request-id` value in error logs so that us
215
214
216
215
### REpresentational State Transfer (REST)
217
216
REST is an architectural style with broad reach that emphasizes scalability, generality, independent deployment, reduced latency via caching, and security. When applying REST to your API, you define your service’s resources as a collections of items.
218
-
These are typically the nouns you use in the vocabulary of your service. Your service's [URLs](#URLS) determine the hierarchical path developers use to perform CRUD (create, read, update, and delete) operations on resources. Note, it's important to model resource state, not behavior.
217
+
These are typically the nouns you use in the vocabulary of your service. Your service's [URLs](#uniform-resource-locators-urls) determine the hierarchical path developers use to perform CRUD (create, read, update, and delete) operations on resources. Note, it's important to model resource state, not behavior.
219
218
There are patterns, later in these guidelines, that describe how to invoke behavior on your service. See [this article in the Azure Architecture Center](https://docs.microsoft.com/en-us/azure/architecture/best-practices/api-design) for a more detailed discussion of REST API design patterns.
220
219
221
220
When designing your service, it is important to optimize for the developer using your API.
@@ -444,23 +443,23 @@ The REST specification is used to model the state of a resource, and is primaril
444
443
445
444
:ballot_box_with_check:**YOU SHOULD** pattern your URL like this to perform an action on a resource
@@ -542,7 +541,7 @@ The value of the `filter` option is an expression involving the fields of the re
542
541
543
542
Example: return all Products whose Price is less than $10.00
544
543
545
-
```http
544
+
```text
546
545
GET https://api.contoso.com/products?`filter`=price lt 10.00
547
546
```
548
547
@@ -566,7 +565,7 @@ not | Logical negation | not price le 3.5
566
565
**Grouping Operators** | |
567
566
( ) | Precedence grouping | (priority eq 1 or city eq 'Redmond') and price gt 100
568
567
569
-
:white_check_mark:**DO** respond with an error message as defined in the [Handling Errors](handling-errors) section if a client includes an operator in a `filter` expression that is not supported by the operation.
568
+
:white_check_mark:**DO** respond with an error message as defined in the [Handling Errors](#handling-errors) section if a client includes an operator in a `filter` expression that is not supported by the operation.
570
569
571
570
:white_check_mark:**DO** use the following operator precedence for supported operators when evaluating `filter` expressions. Operators are listed by category in order of precedence from highest to lowest. Operators in the same category have equal precedence and should be evaluated left to right:
572
571
@@ -590,31 +589,31 @@ The following examples illustrate the use and semantics of each of the logical o
590
589
591
590
Example: all products with a name equal to 'Milk'
592
591
593
-
```http
592
+
```text
594
593
GET https://api.contoso.com/products?`filter`=name eq 'Milk'
595
594
```
596
595
597
596
Example: all products with a name not equal to 'Milk'
598
597
599
-
```http
598
+
```text
600
599
GET https://api.contoso.com/products?`filter`=name ne 'Milk'
601
600
```
602
601
603
602
Example: all products with the name 'Milk' that also have a price less than 2.55:
604
603
605
-
```http
604
+
```text
606
605
GET https://api.contoso.com/products?`filter`=name eq 'Milk' and price lt 2.55
607
606
```
608
607
609
608
Example: all products that either have the name 'Milk' or have a price less than 2.55:
610
609
611
-
```http
610
+
```text
612
611
GET https://api.contoso.com/products?`filter`=name eq 'Milk' or price lt 2.55
613
612
```
614
613
615
614
Example: all products that have the name 'Milk' or 'Eggs' and have a price less than 2.55:
616
615
617
-
```http
616
+
```text
618
617
GET https://api.contoso.com/products?`filter`=(name eq 'Milk' or name eq 'Eggs') and price lt 2.55
619
618
```
620
619
@@ -639,17 +638,17 @@ Each expression in the `orderby` parameter value may include the suffix "asc" fo
639
638
:white_check_mark:**DO** respond with an error message as defined in the [Handling Errors](#Handling-errors) section if the client requests sorting by a field that is not supported by the operation.
640
639
641
640
For example, to return all people sorted by name in ascending order:
642
-
```http
641
+
```text
643
642
GET https://api.contoso.com/people?orderby=name
644
643
```
645
644
646
645
For example, to return all people sorted by name in descending order and a secondary sort order of hireDate in ascending order.
647
-
```http
646
+
```text
648
647
GET https://api.contoso.com/people?orderby=name desc,hireDate
649
648
```
650
649
651
650
Sorting MUST compose with `filter`ing such that:
652
-
```http
651
+
```text
653
652
GET https://api.contoso.com/people?`filter`=name eq 'david'&orderby=hireDate
654
653
```
655
654
will return all people whose name is David sorted in ascending order by hireDate.
@@ -691,7 +690,7 @@ Azure services need to change over time. However, when changing a service, there
691
690
692
691
:white_check_mark:**DO** use an `api-version` query parameter with a `YYYY-MM-DD` date value, with a `-preview` suffix for a preview service.
693
692
694
-
```http
693
+
```text
695
694
PUT https://service.azure.com/users/Jeff?api-version=2021-06-04
0 commit comments