Skip to content

Docs menu // HTTP API

[ DOCS ] /docs/card/api

HTTP API

The card studio is a front end for three endpoints, served by Cloudflare Pages Functions from https://junaadh.com. This page describes what they do, from the code. For the language the scripts are written in, see the card guide.

Endpoints#

RequestReturns
GET /api/card/<login>.svgThe card, as an SVG image.
GET /api/card/<login>.jsonThe profile data a script reads, as JSON. The studio draws locally from it.
POST /api/card/scriptsSaves a script and returns its id, for short links.

GET /api/card/<login>.svg#

<login> must be a GitHub username: letters, digits and hyphens, starting with a letter or digit, at most 39 characters. Anything else is a 400. The .svg extension is optional; without any extension you get the SVG.

Query parameters#

The script comes from exactly one of these, checked in this order:

NameMeaning
scriptA saved script id (11 letters and digits, from POST /api/card/scripts). 400 if it is not an id or nothing is saved under it.
sA script carried in the URL, as the studio encodes it: deflate-compressed and base64url (leading z), or plain base64url (leading p). At most 6,144 characters, and 24 KB once decoded. 400 if it cannot be decoded.
presetA built-in script. Default classic. An unknown id is a 400 that lists the valid ones: classic, languages, heatmap, badge, terminal, synthwave, repos, minimal.

Every other parameter is handed to the script, which reads it with card.param(name, fallback). script, s and preset are never passed on. The limits:

  • at most 16 such parameters;
  • names of 1 to 32 characters from A-Z a-z 0-9 _ . -;
  • values of up to 100 characters;
  • if a name is repeated, the first value is used.

A request that breaks one of these is a 400 with a message saying which.

Examples
https://junaadh.com/api/card/octocat.svg
https://junaadh.com/api/card/octocat.svg?preset=terminal&accent=%23f0883e
https://junaadh.com/api/card/octocat.svg?preset=classic&theme=light
https://junaadh.com/api/card/octocat.svg?script=Kx9fQ2mZ7aB&theme=light

A script that does not compile, or faults, still gets status 200: the body is the report drawn as an image (see errors as images), so it shows in a README. It is not cached. Problems with the data or the request are not 200; see status codes.

GET /api/card/<login>.json#

The profile the script sees, plus avatar, which is a data: URL (or an empty string) and is only used by card.avatar. Query parameters are ignored.

Fields
login, name, bio, location                      strings (name falls back to the login)
followers, following, repos, stars, forks         numbers
commits (this calendar year), pullRequests, issues, contributedTo   numbers (0 without a token)
joined                                            year the account was created
contributions                                     last 365 days
days                                              daily contributions, oldest first, up to 371
languages                                         up to 8 of { name, color, share }
top                                               up to 6 of { name, description, language, stars, forks }
avatar                                            data: URL or ""

Responses carry cache-control: public, max-age=3600 and an x-card-source header (graphql or rest) that tells you how complete the data is. Errors are JSON: { "error": "…" }.

POST /api/card/scripts#

Saves a script so an embed can say ?script=<id> instead of carrying it. The body is the script text, sent as text/plain.

Request
curl -X POST https://junaadh.com/api/card/scripts \
  -H 'content-type: text/plain' \
  --data-binary @card.eit
Response
{ "id": "Kx9fQ2mZ7aB" }
  • The id is 11 characters derived from the SHA-256 of the script. The same script always has the same id, and an id that exists is never overwritten.
  • The script is rendered once against a sample profile and must finish cleanly. A script that does not compile, or that faults on that render, is refused with 422; one that passes is stored even if it later faults for particular data.
  • The body is read with a hard cap of 16 KB whatever the content-length says. The request must come from this site: its Origin header has to match, or the answer is 403.
  • Scripts are kept for good, because short links live in READMEs. Rate limiting is done at the edge, not by this endpoint.
  • Scripts are stored in a Cloudflare KV namespace. Without one the endpoint answers 501.
StatusWhenBody
200Saved, or already saved.{ "id" }
400The body is empty or not valid UTF-8.{ "error" }
403The Origin header is missing or is not this site.{ "error" }
413More than 16 KB (16,384 bytes).{ "error" }
415The content-type does not start with text/plain.{ "error" }
422The script does not compile, or faults when rendered against the sample profile.{ "error", "report" }, the report being the compiler's diagnostic
501No KV namespace is bound (short links are not configured).{ "error" }

Every response from this endpoint is cache-control: no-store. The functions send no CORS headers, so the studio calls it from the same origin.

Caching#

  • GitHub data: 1 hour. Profile data is cached per login (case-insensitive) and refetched once it is an hour old. A user GitHub does not know is remembered for 10 minutes, and a rate limit or upstream failure for 1 minute, so repeated bad requests do not reach GitHub each time.
  • SVG: 1 hour, then stale while it refreshes. The response says public, max-age=3600, stale-while-revalidate=86400. On the server a good card is kept for a day; after the first hour it is still served at once while a new one is drawn in the background. The cache key is the login and the query with its parameters sorted, so the same card is one entry whatever order the parameters came in. A cached card is found from the query alone, before any saved script is looked up or any s is decoded.
  • Errors are never cached. Every error response, including the image for a script with a mistake, says no-store and is not kept on the server.

Headers#

HeaderValue
content-typeimage/svg+xml; charset=utf-8 (application/json for .json and the scripts endpoint)
content-security-policydefault-src 'none'; style-src 'unsafe-inline'; img-src data: on every SVG, errors included
x-content-type-optionsnosniff on every SVG and JSON response
cache-controlAs in caching: public, max-age=3600, stale-while-revalidate=86400 for a card, public, max-age=3600 for .json, no-store for errors
x-card-sourcegraphql when the data came from GitHub's GraphQL API with a token, rest for the fallback
x-card-noteOnly with rest: no GITHUB_TOKEN: public data only; contributed-to is empty

Status codes#

StatusMeaning
200A card, or the diagnostic image for a script that does not compile or faults.
400Invalid username; too many, badly named or too long parameters; unknown preset; script that is not an id or is not saved; s that is too long or cannot be decoded.
404GitHub has no such user.
414The query string is longer than 2,048 characters, not counting the s value (which has its own limit of 6,144 characters).
500The card could not be rendered (an unexpected error).
502GitHub failed or refused: an error status, a rejected token, an unanswerable query or the anonymous rate limit.

Error bodies match the request: an SVG error card (headed eitri // card api) for .svg requests so it is visible in a README, and { "error": "…" } for .json.

Without a GitHub token#

With a GITHUB_TOKEN secret on the server the data comes from GitHub's GraphQL API: only public data is requested, private repositories are never counted, and contributions come from the public calendar. Without one, the API falls back to GitHub's public, unauthenticated endpoints (the REST and search APIs and the public contributions page) and the data has small gaps. The response says which with x-card-source.

  • contributedTo is 0: GitHub has no public source for it.
  • days and contributions are read from the public contributions page, commits (this calendar year), pullRequests and issues from the search API. Each of these falls back to 0 (or an empty days) if GitHub refuses; anonymous search allows about 10 requests a minute per IP, and results are cached for an hour.
  • languages come from each repository's main language (each repository counts once), with built-in colours for common languages (grey for the rest), instead of per-language byte counts.
  • Only the 100 most recently pushed repositories the user owns are looked at, minus forks. GitHub's anonymous rate limit is low; when it is hit the card answers 502 until the limit resets.