-
Notifications
You must be signed in to change notification settings - Fork 3
feat: AIP-121 – Resource-oriented Design #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lukesneeringer
wants to merge
5
commits into
main
Choose a base branch
from
aip-121
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # Resource-oriented design | ||
|
|
||
| Resource-oriented design is a pattern for specifying API services, based on | ||
| several high-level design principles (most of which are common to recent public | ||
| HTTP APIs): | ||
|
|
||
| - The fundamental building blocks of an API are individually-named _resources_ | ||
| (nouns) and the relationships and hierarchy that exist between them. | ||
| - A small number of standard _operations_ (verbs) provide the semantics for | ||
| most common operations. However, custom operations are available in | ||
| situations where the standard operations do not fit. | ||
| - Stateless protocol: Each interaction between the client and the server is | ||
| independent, and both the client and server have clear roles. | ||
|
|
||
| Readers might notice similarities between these principles and some principles | ||
| of [REST][]; resource-oriented design borrows many principles from REST, while | ||
| also defining its own patterns where appropriate. | ||
|
|
||
| ## Guidance | ||
|
|
||
| When designing an API, consider the following (roughly in logical order): | ||
|
|
||
| - The resources (nouns) the API will provide | ||
| - The relationships and hierarchies between those resources | ||
| - The schema of each resource | ||
| - The operations (verbs) each resource provides, relying as much as possible on | ||
| the standard operations. | ||
|
|
||
| ### Resources | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A couple of immediate questions...
|
||
|
|
||
| A resource-oriented API **should** generally be modeled as a resource | ||
| hierarchy, where each node is either an individual resource or a collection of | ||
| resources. | ||
|
|
||
| A _collection_ contains resources of _the same type_. For example, a publisher | ||
| has the collection of books that it publishes. A resource usually has fields, | ||
| and resources may have any number of sub-resources (usually collections). | ||
|
|
||
| **Note:** While there is some conceptual alignment between storage systems and | ||
lukesneeringer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| APIs, a service with a resource-oriented API is not necessarily a database, and | ||
| has enormous flexibility in how it interprets resources and operations. API | ||
| designers **should not** tightly couple their API surface to their underlying | ||
| database system. | ||
|
|
||
| ### Operations | ||
|
|
||
| Resource-oriented APIs emphasize resources (data model) over the operations | ||
| performed on those resources (functionality). A typical resource-oriented API | ||
| exposes a arbitrary number of resources with a small number of operations on | ||
| each resource. The operations can be either the standard operations or custom | ||
| operations. | ||
|
|
||
| **Note:** A custom operation in resource-oriented design does _not_ entail | ||
| defining a new or custom HTTP method. Custom operations use traditional HTTP | ||
| methods (usually `POST`) and define the custom verb in the URI. See AIP-136 for | ||
| more detail. | ||
|
|
||
| Resources **should** include all of the standard operations; however, resources | ||
| **may** exclude some standard operations if there is a justification for doing | ||
| so (for example, a read-only resource would exclude all write operations). | ||
|
|
||
| Similarly, services **should** prefer standard operations over custom | ||
| operations; the purpose of custom operations is to define functionality that | ||
| does not cleanly map to any of the standard operations. Custom operations offer | ||
| the same design freedom as traditional [RPC][] APIs, which can be used to | ||
| implement common programming patterns, such as database transactions, import | ||
| and export, or data analysis. | ||
|
|
||
| ### Stateless protocol | ||
|
|
||
| As with most public APIs available today, resource-oriented APIs **must** | ||
| operate over a stateless protocol: The fundamental behavior of any individual | ||
| request is independent of other requests made by the caller. | ||
|
|
||
| In an API with a stateless protocol, the server has the responsibility for | ||
| persisting data, which may be shared between multiple clients, while clients | ||
| have sole responsibility and authority for maintaining the application state. | ||
|
|
||
| [rest]: https://en.wikipedia.org/wiki/Representational_state_transfer | ||
| [rpc]: https://en.wikipedia.org/wiki/Remote_procedure_call | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| id: 121 | ||
| state: approved | ||
| created: 2019-01-26 | ||
| placement: | ||
| category: resource-design | ||
| order: 10 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.