Skip to content

feat: public read API and Atom feeds - #98

Merged
brendt merged 7 commits into
dev-null-sh:productionfrom
xHeaven:feat/public-api
Oct 16, 2026
Merged

brendt merged 7 commits into
dev-null-sh:productionfrom
xHeaven:feat/public-api

Conversation

@xHeaven

@xHeaven xHeaven commented Oct 15, 2026

Copy link
Copy Markdown
Member

Summary

A public, read-only JSON API under /api/v1, and an Atom feed for every profile. No tokens and no sign-in. It returns exactly what a guest's link preview may already show, so pending, rejected and deleted commits never leak.

Scope note: PRODUCT.md lists "public API" under Deliberately excluded for now and says everything except the landing page needs login. This was requested explicitly, so I built it as narrowly as I could: read-only, no API tokens, and the same visibility rules as link previews. PRODUCT.md now says what is public (Operating Context + Capabilities), and the exclusion now reads "a write API or API tokens". I left TODO.md for you to word.

Endpoints

Endpoint Returns
GET /api/v1/users/{username} The public profile fields plus commits_count, followers_count, following_count
GET /api/v1/users/{username}/commits Top-level commits, newest first, cursor-paginated (20 per page). ?replies=1 lists the user's replies instead, like the profile's Replies tab
GET /api/v1/commits/{id} One commit. 404 for pending, rejected, deleted and unknown ids
GET /@{username}/feed.atom Atom 1.0 feed of the latest 50 approved top-level commits

A commit has id, short_hash (last 7 hex characters of the UUID, the same as shortHash() in utils.ts), body, parent_id, html_url (commit.show), created_at (ISO 8601 UTC), stars_count, replies_count, link_preview (url, title, description, image_url, site_name, or null) and author.
A user has id, username, name, avatar_url, bio, company, location, website, github_url, html_url, feed_url and created_at, plus the counts on the profile endpoint. Email, github_id, preferred_lane and remember_token are never included, and the resources list every field explicitly.

Visibility

The rules are the ones loadPublicPreview() and loadPublicCounts() already use. They are now also a CommitBuilder::withPublicPreview() scope, so lists don't make a query per commit:

  • Only approved() commits. Soft-deleted commits are left out of lists, and asking for one directly is a 404.
  • replies_count only counts approved, non-deleted replies. commits_count only counts approved commits.
  • parent_id is only set while the parent is approved and not deleted. Otherwise it is null, so a reply under a pending parent can't reveal that the parent exists, or its UUIDv7 timestamp.
  • A pending or rejected commit gets the same 404 as an id that doesn't exist.

Atom feed

  • Built with XMLWriter in a RenderUserFeed action, like the OG image actions, so escaping is handled by the writer. Control characters that XML 1.0 can't carry, even escaped, are stripped, which keeps the feed well-formed for any commit body.
  • The feed <id> is urn:uuid:{user id} and each entry's <id> is urn:uuid:{commit id}. They stay the same when a GitHub username changes, even though the links change.
  • The entry title is the squished body cut at 72 characters on a word boundary (a git subject line), and content type="text" holds the full body.
  • Cache-Control: public, max-age=300 and an ETag through Laravel's cache.headers middleware, so readers that revalidate get a 304.
  • Discovery: <link rel="alternate" type="application/atom+xml"> is added to the profile's guest preview in app.blade.php, next to the OG tags. Crawlers and feed readers are guests, so that's the HTML they get.

Rate limit and CORS

  • A named api limiter of 60 requests a minute per IP, defined next to commits in AppServiceProvider. It returns Laravel's standard JSON 429 with Retry-After and X-RateLimit-* headers.
  • There's no config/cors.php. The framework default already allows any origin on api/*, and a test now covers it (Access-Control-Allow-Origin: *).
  • routes/api.php follows the cli group: Route::prefix('v1')->middleware('throttle:api'), with api-user.show, api-user-commit.index and api-commit.show. Errors under api/* were already JSON.

Try it

curl -s https://dev-null.sh/api/v1/users/nunomaduro | jq
curl -s https://dev-null.sh/api/v1/users/nunomaduro/commits | jq '.data[] | {short_hash, body}'
curl -s "https://dev-null.sh/api/v1/users/nunomaduro/commits?cursor=$(curl -s https://dev-null.sh/api/v1/users/nunomaduro/commits | jq -r .meta.next_cursor)" | jq '.data | length'
curl -s 'https://dev-null.sh/api/v1/users/nunomaduro/commits?replies=1' | jq '.data[0].parent_id'
curl -s https://dev-null.sh/api/v1/commits/{id} | jq
curl -s https://dev-null.sh/@nunomaduro/feed.atom

README.md has a short "Public API" section with the endpoints and the feed URL.

Media

These are backend changes, so every image is a local mock page that shows real curl/jq output and responses from my worktree on localhost:8105, with realistic seeded data. The local server ran with APP_DEBUG=false, so errors look like they do in production.

Paging through next_cursor

Paging through commits with next_cursor

MP4

GET /api/v1/users/{username}

Light Dark
User light User dark

GET /api/v1/users/{username}/commits

One commit with a link preview, plus meta.

Light Dark
Commits light Commits dark

GET /api/v1/commits/{id}

A reply with its public parent, a pending commit (404), and a link preview.

Light Dark
Commit light Commit dark

Rate limit and CORS

Light Dark
Limits light Limits dark

The feed: discovery link, cache headers, 304, XML

Light Dark
Feed light Feed dark

In a feed reader

A local mock reader that parses the real feed.atom with DOMParser. The selected entry has & and <script> in its body, and they come through as text.

Desktop light Desktop dark
Reader light Reader dark
Mobile light Mobile dark
Reader mobile light Reader mobile dark

Testing

  • New tests:
    • Api/UserControllerTest: the exact profile JSON with public counts (pending, rejected and deleted commits don't count), hidden fields never present, and a 404 for an unknown username.
    • Api/UserCommitControllerTest: top-level only and newest first, with pending, rejected, deleted and other users' commits left out. Also ?replies=1, cursor paging that keeps replies in links.next, validation of replies, a 404 for an unknown user, and the same query count for 1 and 6 commits (no N+1) on both lists.
    • Api/CommitControllerTest: the exact commit JSON (short hash, URLs, author), approved-only reply count and star count, parent_id only for a public parent (approved, pending, rejected and deleted cases), link preview fields, hidden user fields, a 404 for pending, rejected, deleted, unknown and malformed ids, JSON without an Accept header, CORS, and 60 requests then a 429, with other IPs unaffected.
    • UserFeedControllerTest: a parsed feed with its id, title, subtitle, updated, author, self and alternate links, and entry ids, links, dates and content. Also what's excluded, the 50 limit, 72-character titles, escaping (&, ", <script>, ]]>) and stripped control characters, an empty feed, cache headers with an ETag and a 304, and a 404 for an unknown user.
    • UserControllerTest: the guest preview has the rel="alternate" feed link, and the signed-in page doesn't. AppServiceProviderTest: the api limiter.
  • Results (targeted, not the full suite): pest on the new and affected files, plus ArchTest, CommitBuilderTest, CommitControllerTest and the Cli controllers: 135 passed. Pint and Rector are clean on the touched files, PHPStan (level max) reports no errors on the touched app and route files, and pest --type-coverage --min=100 reports 100%. bun run build and tsc --noEmit pass (no frontend changes).
  • By hand: xmllint --noout accepts the seeded feed.

Known gaps

  • Feed requests start a session. The feed is a web route like the OG image routes, so every fetch sets session and XSRF cookies, and with the database session driver each new reader writes a session row. Moving public read routes off the session middleware would be a separate change across all of them.
  • Feed discovery is guest-only. Signed-in users get the Inertia profile, which has no <link rel="alternate">. Readers and crawlers are guests, so they find it.
  • The feed isn't rate limited, the same as the OG images. It relies on the five-minute cache and ETag.
  • 404 messages are Laravel's default (No query results for model [App\Models\Commit] {id}). They look the same for pending, rejected, deleted and unknown ids, so they don't reveal whether a commit exists.
  • Coverage wasn't measured locally, because no Xdebug/PCOV is installed. The new code has no untested branches, but CI's 100% coverage gate is the real check.

@brendt
brendt merged commit 3a8181f into dev-null-sh:production Oct 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants