fandom-api-types Docs

Overview

Everything you need to know to start shipping with fandom-api-types.

fandom-api-types packages every TypeScript interface used by the Fandom + MediaWiki ecosystem into a single zero-runtime dependency. The library mirrors real REST/Action/Fandom responses so your SDKs, bots, and automation scripts can compile against the same payloads wikis actually emit.

Why fandom-api-types?

  • Tracks the MediaWiki REST API v1, Action API, and platform specific endpoints in one place.
  • Ships both curated handwritten models and auto-generated response types pulled from live API responses.
  • Includes Routes helpers so you can build URLs with type safety instead of string concatenation.
  • Zero runtime footprint—importing the package only pulls in interfaces and type aliases.

Install

pnpm add fandom-api-types
npm install fandom-api-types
yarn add fandom-api-types
bun add fandom-api-types

Export map at a glance

NamespacePurpose
RestREST v1 summaries for pages, revisions, search, site info, categories, media, and users.
ActionAction API query, parse, edit, and revisions envelopes.
FandomArticle, discussion, feed, and user payloads from Fandom-specific endpoints.
GeneratedSchemas captured from real responses via scripts/generate-types.ts.
RoutesURL builders for REST, Action, and Fandom endpoints (no network calls involved).

Import what you need:

import { Rest, Action, Fandom, Generated, Routes } from "fandom-api-types";

const latest: Rest.MWRevisionSummary = {
  id: 42,
  timestamp: new Date().toISOString(),
};
const query: Action.MWQueryResponse = { query: { pages: {} } };
const article: Fandom.FandomArticleDetails = {
  id: 1,
  title: "Main Page",
  url: "/wiki/Main_Page",
  wikiId: 177,
};
const url = Routes.rest.page("https://community.fandom.com", "Main Page");

Type layout

  • src/rest/v1 – REST v1 contracts such as MWRestPage, MWRevisionSummary, MWSearchResponse, and MWSiteInfo.
  • src/action – Action API helpers for query, parse, edit, and revisions. These reuse REST types where the shapes overlap.
  • src/fandom – Definitions for /api/v1 surfaces (articles, discussion, feeds, users) exposed uniquely on Fandom.
  • src/generated – Auto-generated files (do not edit by hand) that mirror entire JSON payloads returned by real wikis.
  • src/routes.ts – String helpers for REST, Action, and internal Fandom endpoints. These are safe to call in any runtime because they only assemble URLs.

Working with Routes

Routes keeps endpoint construction consistent:

const wiki = "https://genshin-impact.fandom.com";

const restPageUrl = Routes.rest.page(wiki, "Archon_Quest");
const searchUrl = Routes.rest.search(wiki, "Hilichurl", 10);
const actionQueryUrl = Routes.action.query(wiki, {
  action: "query",
  list: "search",
  srsearch: "lore",
});
const parseUrl = Routes.action.parse(wiki, "Traveler", {
  prop: "text|categories",
});
const discussionUrl = Routes.fandom.discussionPosts(wiki, "12345", 25);

Each helper handles URL encoding, default params (like format=json), and optional arguments (limit, prop, etc.).

How is this guide?

On this page