API design conventions
These are the rules the Aveloxis REST API is designed and documented by.
They are modeled on the
Swift API Design Guidelines,
which are about how a call reads where it is used, and they apply those
ideas to HTTP and JSON. The reference follows them, and
scripts/openapi_routes_test.go checks the ones a program can check (see
the end of this page).
The second half of the page is the contract every operation shares: access, errors, rate limits, caching and time. The reference does not repeat it.
Fundamentals
Clarity at the point of use is the most important goal. A call is written once and read many times, in scripts, notebooks and logs. Judge a design by reading a whole request in context:
GET /api/v1/repos/42/contributions/affiliations?since=2025-01-01should say what it returns without a trip to this documentation.Clarity is more important than brevity. A path segment is not shorter for its own sake:
contributions/identitiesrather thancontrib-ids.Every operation is documented. Writing the entry is part of designing the operation. If its behavior cannot be described in a few sentences, the design is probably wrong.
Naming
Use words that remove ambiguity
Include every word needed to avoid ambiguity. The roster of people who contributed in a window is
contributions/identities; the Augur-compatiblecontributorsroute returns aggregated counts. The two names say which is which.Omit needless words.
/repos/42/stats, not/repos/42/repo-stats: the path already says whose statistics they are.Name parameters and fields for their role, not their type.
sinceanduntil, notdate1anddate2;retention_threshold, notn.Booleans read as assertions about the thing they describe:
scanned,starred,is_osi,is_admin,editable.
Use terminology well
Use a term of art only in its established meaning: SBOM, purl, CycloneDX, SPDX, OSV, libyear, ETag. Do not coin a new word for an established idea, and do not use an established word for a new one.
Use one term per concept, everywhere: in paths, field names, the reference and the guide.
Concept
Term
In paths and fields
A collected repository
repository
repos,repo_idA user’s set of repositories and organizations
group
groups,group_idAn administrator-curated set of groups
collection
collections,collection_idA GitHub organization or GitLab group
organization
orgA person, across identities
contributor
contributors,cntrb_idA repository or organization being compared
entity
entities(repo:42,org:github.com/chaoss)What a caller may read
scope
repo_out_of_scopeA signed-in web session’s Bearer token
session token
sessionTokenschemeAn administrator-granted Bearer token
API token
apiTokenscheme,avx_…A fair-use limit
quota
quota,capacity_limitThe repositories an account may hold
allocation
kind: allocationAvoid abbreviations, except where they are the established name:
repoin paths and fields is the precedent of every existing client, andcntrb_idis the stored column clients already read.Embrace precedent. The Augur-compatible routes keep Augur’s paths and parameter names (
begin_date,end_date,period), because 8Knot and other Augur clients call them as they are. Routes that predate these rules keep their names: renaming a path or field breaks every client that uses it.
Spelling
Paths are lower case, with plural nouns for collections of resources (
/groups/{groupID}/repos) and-between words.Path parameters are lowerCamelCase and end in
IDfor identifiers ({repoID},{groupID}), the precedent of the existing routes.Query parameters and JSON fields are
snake_case. Identifiers end in_id, instants in_at(created_at,reset_at). Two older answers use Go field names instead (the mailing-list statistics and the single-repository Augur lookup); the reference marks them.
Name operations by what they do
Each operation has an operationId, the name a generated client uses for
it, shown in every reference entry.
A read (GET) is a noun phrase naming what it returns:
repositoryStats,groupRepositories,apiTokens. A GET has no side effects that matter to the caller, so a verb such asgetorlistadds nothing.A change is an imperative verb phrase:
createGroup,addRepositoriesToGroup,revokeAPIToken.Paired operations read as a pair:
starRepository(PUT) andunstarRepository(DELETE).Acronyms are uniformly cased: lower case at the start of a name (
apiTokens,sbomDocument), upper case elsewhere (repositorySBOM,grantAPIToken).Augur-compatible operations are
augurfollowed by Augur’s metric name (augurIssuesNew).
Documentation
Every operation has a summary of one sentence. A read says what it returns (“Returns the weekly activity series of a repository.”); a change says what it does, in the third person (“Revokes an API token.”).
The description adds what a schema cannot say: what edge values mean, the order of a list, defaults and caps, and what each status code means for this operation. It ends with the handler that serves it (“Handler:
handleRepoStats.”), so a reader can go from the reference to the source.Document the cost of anything that is not cheap. The Swift guidelines ask for the complexity of any property that is not O(1); here, an operation that is not a cached or indexed read says what it costs and how its input is bounded (at most 500 ids per call, at most seven entities, a
limitcapped at 100).Document every failure. Each response code an operation can return is in its entry. The ones many operations share are written once, under “Shared responses” at the end of the reference, and each entry links there.
Access
Every operation states who may call it. There are five classes, written in
the spec as the operation’s security requirements:
Access |
Who may call |
|
|---|---|---|
Public |
Anyone; no token ( |
|
Read |
A session or an API token; anonymous callers too while |
|
Signed in |
A session or an API token, always |
|
Session |
A signed-in session; an API token is refused ( |
|
Administrator |
An administrator’s signed-in session; an API token is refused even when an administrator owns it |
|
Both token kinds are sent as Authorization: Bearer <token>.
Scope. A repository-scoped operation (any /repos/{repoID}/… read)
answers only for repositories in the caller’s groups. An administrator’s
session is unscoped, and so is an anonymous caller where the access class
admits one (api.require_auth off, or an exempt network): scope belongs
to a token’s account, and an anonymous call has none. A signed-in session that follows a link to a
repository outside its groups has the repository added to its “Shared
with Me” group, and the answer carries X-Aveloxis-Added-To-Group once.
The addition happens before the operation runs, so the header rides on
whatever that request answers, an error (400, 404, 429, 500)
included;
an API token is refused with 403 repo_out_of_scope and a body that says
how to add the repository. The guide
has the details and the caps.
Errors
A status code means the same thing on every operation:
Code |
Meaning |
Body |
|---|---|---|
|
The request is malformed: an id that is not an integer, a value outside its set, a missing parameter or field |
One sentence, |
|
No valid token where one is needed: missing, unknown, expired or revoked |
|
|
A valid token that may not do this: out of scope ( |
JSON |
|
No such resource |
One sentence |
|
A conflict with stored state the entry describes (a setting |
One sentence or JSON, per entry |
|
Understood but not acted on: the account e-mail could not be sent a confirmation |
JSON naming why |
|
A rate limit: retry after |
|
|
A server-side failure. The body never carries the cause; it is in the api log |
|
|
Try again: a presented token could not be checked because the database failed (the token was not rejected), or the request ran past |
|
A client should treat 401 as “the token is gone” and 503 as “try
again”; they are never mixed. Every 401 and 403 is sent
Cache-Control: private, no-store.
Rate limits and quotas
Every request passes the rate limiter. A caller without a valid token is limited per address; a session and an API token are counted against their own quotas from every address. The limits, their defaults and the quota modes are described in the guide’s Rate limits section.
An answer counted against an enforced quota carries the IETF RateLimit
and RateLimit-Policy header fields and the older X-RateLimit-Limit,
X-RateLimit-Remaining and X-RateLimit-Reset, all readable by
cross-origin browser clients. A refusal by a quota is the
capacity_limit body: 429 with Retry-After for a rate quota, 403
without one for the repository allocation, which does not free up with
time.
Caching and validators
A repository’s own read operations whose reference entry lists 304 are
served from a response cache that is kept until the repository’s state
changes — it is collected or scanned again, or a repair outside a
collection rewrites its data — or, for an answer over a window, until that
window moves (no answer expires on a timer):
the answer carries an
ETag; send it back asIf-None-Matchand an unchanged answer is304 Not Modifiedwith no body;Cache-Control: no-cachemarks an answer any caller may be given (a client revalidates each time), andprivate, no-storean answer about this caller, which nothing may store;X-Cache: hitsays the answer came from the cache.
The guide describes when the cache is on and what it keeps.
Times and windows
Instants are RFC 3339 strings in UTC (
2026-10-10T14:02:11Z).Days are
YYYY-MM-DDand mean UTC days. A day parameter that does not parse is a400on every operation (since 0.29.99; the repository and contribution operations fell back to their default before). A window whose start is not before its end is a400everywhere.untilis inclusive on the repository series and contribution operations, and exclusive on the comparison, which also ends at the last complete bucket. The guide explains why both stay as they are.
Compatibility
One field name for a metric’s number. The comparison series (
/compare) and the single-number Augur-compatible metric routes carry the number in a field namedvalue. Augur names that field per metric (stars,forks,commit_count, …); a client moving from Augur readsvaluehere instead. The exceptions, each marked in the reference:/repos/{id}/watcherskeeps Augur’swatcherskey (the one series whose shape already matched Augur’s when this rule was decided);/repos/{id}/code-changes-linesis a two-number row (added,removed) under Augur’s names; and the older native weekly series of/repos/{id}/timeseriescarriescount(unchanged since it shipped; its clients predate the rule). The 0.29.111 release notes record the decision.Adding an operation, an optional parameter or a field is a compatible change. Clients must ignore fields they do not know.
Removing or renaming an operation, a parameter or a field, or changing what a field means, is a breaking change and is called out in the release notes.
Absent and
nullare different where the reference says so: an omitted field usually means “not known” (no snapshot yet), never zero.
What the tests check
scripts/openapi_routes_test.go reads the spec and the route
registrations in internal/api and fails the build when:
a registered route is not in the spec, or a spec path is not registered;
a path parameter is missing, or a declared query parameter is not one the handler reads (and the other way round);
an operation’s
securityis not the access its handler enforces;an operation leaves out a response its access or its handler implies:
429and503everywhere,401off the public paths,403where the handler refuses by role or scope,500where it can fail on the server,304withETagandIf-None-Matchon the response-cached routes;an
operationIdis not lowerCamelCase or not unique, a read’s name starts with a verb such asget, a summary is not one sentence ending in a period, an operation does not have exactly one tag, a description does not cite its handler, or a$refdoes not resolve.
The design rules above that need judgment (the right words, the cost notes) are checked by review.