This site has a small public API: GET /api/articles returns everything written here as JSON, filterable by collection and tag. It is one file of about 150 lines, half of them comments. It is also a good place to practise the decisions that matter on large APIs, because there is nothing else in the way.
RSS already existed, which raises the obvious question of why bother. RSS is built for feed readers: no tags, no reading time, no summary points, and dates in a format you cannot sort as text. This is the same content shaped for a program.
Do not publish your internal type
The site already had a type describing every article. The tempting version of this endpoint serialises that type and is finished in five minutes.
The internal type carries fields that only mean something to this site's build: a path to the React component that renders the page, a path relative to the site root. Publish those and every future change to how the site builds itself becomes a breaking change for anyone reading the API. So the endpoint has its own wire type, mapped explicitly: no build plumbing, and absolute URLs so a consumer never has to know the origin.
Reject bad input; do not quietly fix it
?limit=500 could be clamped to 100 and served. It is rejected with a 400 and a message saying the valid range instead. A consumer who asked for 500 and silently got 100 has a bug they will find much later, probably when they assume they have everything. Same for an unknown collection: an explicit error naming the valid values.
The exception proves the rule: an unknown tag returns 200 with an empty list. A tag that matches nothing is a perfectly valid question with a true answer, not a malformed request.
Say how many, and of what
The response carries three numbers, not one:
{
"version": 1,
"count": 5,
"matched": 12,
"total": 45,
"items": [ ... ]
}count is what is in this response, matched is how many fit the filter before the limit, and total is everything. "5 results" on its own leaves a consumer guessing whether there are more. The version field changes only when a field is removed or changes meaning; adding fields is not a breaking change and does not bump it.
Decide what repeated parameters mean
?tag=a&tag=b has to mean something. This endpoint takes the first value rather than erroring. More importantly, that rule has to hold everywhere the handler runs — which is how I found that the local development server parsed repeated parameters the opposite way from production, so the same request returned different articles in each.
Let the cache do the work
The data is identical for everyone and changes only when something is published, so the response is cached at the edge:
cache-control: public, s-maxage=3600, stale-while-revalidate=86400Most requests are served from cache rather than running the function at all, and when a cached copy expires, the stale one keeps being served while a fresh one is fetched. CORS is open, because the content is already public HTML and there is nothing to protect by restricting which site can read it. There is no key and no rate limit for the same reason — metering free access to public pages would be theatre.
Small is where you practise
None of these decisions is specific to a portfolio. A separate wire type, strict input, honest counts, defined behaviour for odd input and caching matched to how often data actually changes are the same calls you make on a large API. On an endpoint this small you can make each one deliberately, and see the whole reason for it in one file.