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: azure/Guidelines.md
+25-27Lines changed: 25 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,12 +46,12 @@ The Microsoft Azure Cloud platform exposes its APIs through the core building bl
46
46
47
47
### HTTP
48
48
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:
49
-
-[Uniform Resource Locators (URLs)](URLS)
50
-
- HTTP Methods
51
-
- Request & Response Headers
52
-
- Bodies
53
49
54
-
### Uniform Resource Locators (URLs)
50
+
- Uniform Resource Locators (URLs)
51
+
- HTTP Request / Response Pattern
52
+
- HTTP Query Parameters and Header Values
53
+
54
+
#### Uniform Resource Locators (URLs)
55
55
56
56
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
57
@@ -88,8 +88,6 @@ Some customer-provided path segment values may be compared case-insensitivity if
88
88
89
89
: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
90
91
-
#### Direct Endpoint URLs
92
-
93
91
: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
110
113
111
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
112
115
-
#### Exactly Once Behavior = Client Retries & Service Idempotency
113
+
#####Exactly Once Behavior = Client Retries & Service Idempotency
116
114
117
115
: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
146
149
-
### HTTP Query Parameters and Header Values
147
+
####HTTP Query Parameters and Header Values
150
148
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
149
152
150
: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.
@@ -215,7 +213,7 @@ Your service should include the `x-ms-request-id` value in error logs so that us
215
213
216
214
### REpresentational State Transfer (REST)
217
215
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.
216
+
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
217
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
218
221
219
When designing your service, it is important to optimize for the developer using your API.
@@ -444,23 +442,23 @@ The REST specification is used to model the state of a resource, and is primaril
444
442
445
443
:ballot_box_with_check:**YOU SHOULD** pattern your URL like this to perform an action on a resource
@@ -542,7 +540,7 @@ The value of the `filter` option is an expression involving the fields of the re
542
540
543
541
Example: return all Products whose Price is less than $10.00
544
542
545
-
```http
543
+
```text
546
544
GET https://api.contoso.com/products?`filter`=price lt 10.00
547
545
```
548
546
@@ -566,7 +564,7 @@ not | Logical negation | not price le 3.5
566
564
**Grouping Operators** | |
567
565
( ) | Precedence grouping | (priority eq 1 or city eq 'Redmond') and price gt 100
568
566
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.
567
+
: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
568
571
569
: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
570
@@ -590,31 +588,31 @@ The following examples illustrate the use and semantics of each of the logical o
590
588
591
589
Example: all products with a name equal to 'Milk'
592
590
593
-
```http
591
+
```text
594
592
GET https://api.contoso.com/products?`filter`=name eq 'Milk'
595
593
```
596
594
597
595
Example: all products with a name not equal to 'Milk'
598
596
599
-
```http
597
+
```text
600
598
GET https://api.contoso.com/products?`filter`=name ne 'Milk'
601
599
```
602
600
603
601
Example: all products with the name 'Milk' that also have a price less than 2.55:
604
602
605
-
```http
603
+
```text
606
604
GET https://api.contoso.com/products?`filter`=name eq 'Milk' and price lt 2.55
607
605
```
608
606
609
607
Example: all products that either have the name 'Milk' or have a price less than 2.55:
610
608
611
-
```http
609
+
```text
612
610
GET https://api.contoso.com/products?`filter`=name eq 'Milk' or price lt 2.55
613
611
```
614
612
615
613
Example: all products that have the name 'Milk' or 'Eggs' and have a price less than 2.55:
616
614
617
-
```http
615
+
```text
618
616
GET https://api.contoso.com/products?`filter`=(name eq 'Milk' or name eq 'Eggs') and price lt 2.55
619
617
```
620
618
@@ -639,17 +637,17 @@ Each expression in the `orderby` parameter value may include the suffix "asc" fo
639
637
: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
638
641
639
For example, to return all people sorted by name in ascending order:
642
-
```http
640
+
```text
643
641
GET https://api.contoso.com/people?orderby=name
644
642
```
645
643
646
644
For example, to return all people sorted by name in descending order and a secondary sort order of hireDate in ascending order.
647
-
```http
645
+
```text
648
646
GET https://api.contoso.com/people?orderby=name desc,hireDate
649
647
```
650
648
651
649
Sorting MUST compose with `filter`ing such that:
652
-
```http
650
+
```text
653
651
GET https://api.contoso.com/people?`filter`=name eq 'david'&orderby=hireDate
654
652
```
655
653
will return all people whose name is David sorted in ascending order by hireDate.
@@ -691,7 +689,7 @@ Azure services need to change over time. However, when changing a service, there
691
689
692
690
: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
691
694
-
```http
692
+
```text
695
693
PUT https://service.azure.com/users/Jeff?api-version=2021-06-04
0 commit comments