Repository navigation
docs: Add ADR 0042 - API standards for creating resources #883
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
mike-gorman-bitwarden
wants to merge
1
commit into
main
Choose a base branch
from
docs/adr-0042-api-standards-for-creating-resources
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
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
74 changes: 74 additions & 0 deletions
74
docs/architecture/adr/0042-api-standards-for-creating-resources.md
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,74 @@ | ||
| --- | ||
| adr: "0042" | ||
| status: Proposed | ||
| date: 2026-10-05 | ||
| tags: [server, server-sdk] | ||
| --- | ||
|
|
||
| # 0042 - API standards for creating resources | ||
|
|
||
| <AdrTable frontMatter={frontMatter}></AdrTable> | ||
|
|
||
| ## Notation | ||
|
|
||
| This ADR uses [RFC 2119](https://www.rfc-editor.org/info/rfc2119/) keywords (`MUST`, `MUST NOT`, | ||
| `SHOULD`, `SHOULD NOT`, `MAY`) deliberately. | ||
|
|
||
| ## Context and problem statement | ||
|
|
||
| [ADR-0036](./0036-service-to-service-api-standards.md) requires service-to-service APIs to conform | ||
| to a documented set of standards, and ADR-0039 builds those standards on IETF RFCs. This ADR sets | ||
| how a resource is created: the method, the path, the request, and what a successful response | ||
| returns. Payload shape and errors are set by ADR-0040. | ||
|
|
||
| ## Considered options | ||
|
|
||
| - **`POST` to the collection, returning the new resource.** | ||
| - **`PUT` to a client-chosen ID** as the primary way to create. | ||
| - **`POST` returning only a `Location` header** and no body. | ||
|
|
||
| ## Decision outcome | ||
|
|
||
| Chosen option: **`POST` to the collection, returning the new resource**, because the caller usually | ||
| needs the server-generated ID and the stored representation, and getting both in one response saves | ||
| a second call. | ||
|
|
||
| - The method `MUST` be `POST`, and the path `SHOULD` be the collection, `/api/v1/{resource plural}`. | ||
| - When the service generates the ID, the request `MUST` omit `id`. | ||
| - APIs that support create-or-update `MUST` do so through `PUT` (see ADR-0044). | ||
| - On success, APIs `SHOULD` return `201` but `MAY` return `202` or `204`. | ||
|
|
||
| | Status | Meaning | Body | | ||
| | ---------------- | ---------------------------------------- | ------------------------------------------ | | ||
| | `201 Created` | The resource was created. | The latest representation of the resource. | | ||
| | `202 Accepted` | The resource is scheduled to be created. | The job scheduled to create it (ADR-0045). | | ||
| | `204 No Content` | The resource was created. | Nothing. | | ||
|
|
||
| ```http | ||
| POST /api/v1/users | ||
| Content-Type: application/json | ||
| ``` | ||
|
|
||
| ```json | ||
| { | ||
| "data": { | ||
| "attributes": { | ||
| "firstName": "Bob", | ||
| "lastName": "Smith" | ||
| }, | ||
| "type": "user" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Creating many resources at once is a bulk create (see ADR-0046). | ||
|
|
||
| ### Positive consequences | ||
|
|
||
| - One round trip returns everything a caller needs about the new resource. | ||
| - Creation looks the same on every API. | ||
|
|
||
| ### Negative consequences | ||
|
|
||
| - `201` responses carry the full representation, which is wasted when the caller does not need it. | ||
| `204` remains available for that case. | ||
Oops, something went wrong.
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.