Skip to content

Commit 786c45c

Browse files
authored
Overhaul and expand API guidelines
The exposed interfaces in the API have unfortunately become far too varied over the years, and part of this can be blamed on our lack of intentional design behind them. It was always implicit: design it like it was before. Unfortunately implicit design doesn't scale as more people work on a system, so this change documents a set of design principles that we can rely on to future proof new APIs, as well as apply to legacy APIs down the road. Some notable shifts from where we are today: - All API endpoints must be designed as if its a public API. - `PATCH` should not be used. It is redundant with `PUT` in our use cases. If you want to "replace a resource" (which is uncommon behavior), you would do it via `POST /resource/:id`. - Responses should use noun-based nesting on the object vs being flat (e.g. `{project: {...}` vs `{...}` for a project response). - Identifiers should accept both human-readable identifiers and numeric identifiers. This has regressed quite drastically over the years, both in terms of query params as well as route identifiers. - Identifiers should use common names (`organization`) rather than ambiguous attributes (`organization_id`). Refs #13461
1 parent 90d1aa3 commit 786c45c

File tree

3 files changed

+343
-197
lines changed

3 files changed

+343
-197
lines changed

develop-docs/backend/api/basics.mdx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ sidebar_order: 1
55
This section includes common terms and resources to learn more about API design. If you're new to API design, this is a good place to start.
66

77
## Common Terms
8+
89
- **Resource** is the object you’re performing the action on with your endpoint. For example, in ProjectEndpoint the resource is Project.
9-
- **Resource Identifier** can be an ID, like an event ID, or slug, like an organization slug. Note that it must be unique. For example, Sentry's project resource identifier is \{org_slug}/\{project_slug}, because projects are only unique within their organization. You can find more information about this in the slug vs. ID section.
10+
11+
- **Resource Identifier** can be an ID, like an event ID, or slug, like an organization slug. Note that it must be unique. For example, Sentry's project resource identifier is \{organization}/\{project}, because projects are only unique within their organization. You can find more information about this in the slug vs. ID section.
12+
1013
- **Method** is what you do with the resource. Each endpoint can have multiple methods. For example in ProjectEndpoint, you can have a GET method that returns details of a specific project.
14+
1115
- **Collection** is basically an object type. You can map them to a Django object type like an Organization or a text object like an error.
1216

13-
## Extra Resources
17+
## Additional Reading
18+
1419
The following resources are helpful to learn about general API design best practices:
1520

1621
- **[The Design of Web APIs](https://g.co/kgs/R7rXEk)** is an example-packed guide to designing APIs.
22+
1723
- **[API Design Patterns](https://g.co/kgs/Vfnpe5)** is comprehensive guide on key API patterns.

develop-docs/backend/api/concepts.mdx

Lines changed: 0 additions & 142 deletions
This file was deleted.

0 commit comments

Comments
 (0)