Skip to content

Commit 50b14d3

Browse files
authored
Merge pull request #297 from mikekistler/actions
Update guidance on path structure for actions
2 parents dc18f67 + 64b3c93 commit 50b14d3

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

azure/ConsiderationsForServiceDesign.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,22 @@ As you build out your service and API, there are a number of decisions that can
119119

120120
:ballot_box_with_check: **YOU SHOULD** implement [conditional requests](https://tools.ietf.org/html/rfc7232) early. This allows you to support concurrency, which tends to be a concern later on.
121121

122+
## Action Operations
123+
124+
Most operations conform to one of the standard REST Create, Read, Update, Delete, or List (CRUDL) style of operations. We refer to all other operations as "action" operations. Some examples of action operations are to reboot a VM, or send an email.
125+
126+
It is good practice to define the path for action operations that is easily distinguished from any resource path of the service. When services allow user-specified resource ids (also a good practice), the recommended approach for this is:
127+
1) constrain user-specified resource ids to allow only certain characters, such as alphanumeric and '-' or '_', and
128+
2) use a special character not in the set of valid characters for resource names to distinguish the "action" in the path.
129+
130+
In Azure we recommend distinguishing action operations by appending a ':' followed by an action verb to the final path segment. E.g.
131+
```http
132+
https://.../<resource-collection>/<resource-id>:<action>?<input parameters>
133+
```
134+
135+
Other patterns are possible. The key consideration is to ensure that the path for an action operation
136+
cannot collide with a resource path that contains user-specified resource ids.
137+
122138
## Long-Running Operations
123139

124140
Long-running operations are an API design pattern that should be used when the processing of

azure/Guidelines.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ Note: RFC 1123 defines the date format as a modification of the date format in [
203203

204204
:no_entry: **DO NOT** use "x-" prefix for custom headers, unless the header already exists in production [[RFC 6648](https://datatracker.ietf.org/doc/html/rfc6648)].
205205

206-
#### Additional References
206+
**Additional References**
207207
- [StackOverflow - Difference between http parameters and http headers](https://stackoverflow.com/questions/40492782)
208208
- [Standard HTTP Headers](https://httpwg.org/specs/rfc7231.html#header.field.registration)
209209
- [Why isn't HTTP PUT allowed to do partial updates in a REST API?](https://stackoverflow.com/questions/19732423/why-isnt-http-put-allowed-to-do-partial-updates-in-a-rest-api)
@@ -425,23 +425,20 @@ Both Rectangle and Circle have common fields: `kind`, `fillColor`, `lineColor`,
425425
## Common API Patterns
426426

427427
### Performing an Action
428-
The REST specification is used to model the state of a resource, and is primarily intended to handle CRUD (Create, Read, Update, Delete) operations. However, many services require the ability to perform an action on a resource, e.g. getting the thumbnail of an image, sending an SMS message. It is also sometimes useful to perform an action on a collection.
428+
The REST specification is used to model the state of a resource, and is primarily intended to handle CRUD (Create, Read, Update, Delete) operations. However, many services require the ability to perform an action on a resource, e.g. getting the thumbnail of an image or rebooting a VM. It is also sometimes useful to perform an action on a collection.
429429

430-
:white_check_mark: **DO** pattern your URL like this to perform an action on a resource
430+
:ballot_box_with_check: **YOU SHOULD** pattern your URL like this to perform an action on a resource
431431
**URL Pattern**
432432
```http
433433
https://.../<resource-collection>/<resource-id>:<action>?<input parameters>
434434
```
435435

436436
**Example**
437437
```http
438-
https://.../users/Bob:send-sms?text="Hello"
438+
https://.../users/Bob:grant?access=read
439439
```
440440

441-
**Equivalent to (in C#)**
442-
```users["Bob"].SendSms("Hello")```
443-
444-
:white_check_mark: **DO** pattern your URL like this to perform an action on a collection
441+
:ballot_box_with_check: **YOU SHOULD** pattern your URL like this to perform an action on a collection
445442
**URL Pattern**
446443
```http
447444
https://.../<resource-collection>:<action>?<input parameters>
@@ -460,8 +457,9 @@ Note: To avoid potential collision of actions and resource ids, you should disal
460457

461458
:white_check_mark: **DO** return a `200-OK` when the action completes synchronously and successfully.
462459

463-
:ballot_box_with_check: **YOU SHOULD** use a verb to name your action.
460+
:ballot_box_with_check: **YOU SHOULD** use a verb as the `<action>` component of the path.
464461

462+
:no_entry: **DO NOT** use an action operation when the operation behavior could reasonably be defined as one of the standard REST Create, Read, Update, Delete, or List operations.
465463

466464
### Collections
467465
:white_check_mark: **DO** structure the response to a list operation as an object with a top-level array field containing the set (or subset) of resources.
@@ -984,7 +982,8 @@ Client libraries are required to send telemetry and distributed tracing informat
984982
:white_check_mark: **DO** follow the Azure SDK client guidelines for supporting telemetry headers and Open Telemetry.
985983

986984
:no_entry: **DO NOT** reject a call if you have custom headers you don't understand, and specifically, distributed tracing headers.
987-
#### Additional References
985+
986+
**Additional References**
988987
- [Azure SDK client guidelines](https://azure.github.io/azure-sdk/general_azurecore.html)
989988
- [Azure SDK User-Agent header policy](https://azure.github.io/azure-sdk/general_azurecore.html#azurecore-http-telemetry-x-ms-useragent)
990989
- [Azure SDK Distributed tracing policy](https://azure.github.io/azure-sdk/general_azurecore.html#distributed-tracing-policy)

0 commit comments

Comments
 (0)