跳到正文
DEV Community· Hasan · MyAnimeDex·· 36 分鐘前AI 評分30

Jikan API 停運後,MyAnimeDex 如何遷移至 AniList 而不重寫每個畫面

Jikan shut down. Here's how I moved my anime app to AniList without rewriting every screen

AI 導讀

MyAnimeDex 在 Jikan API 停運後,將資料服務遷移至 AniList GraphQL API,並保留舊有資料格式,避免重寫大部分畫面。遷移時以每次請求至少相隔 350 ms 的佇列、依 Retry-After 重試及快取處理速率限制;重要回應亦會儲存至磁碟,在網絡或 AniList 無法使用時顯示。

正文

In September 2026 the Jikan API, the unofficial MyAnimeList REST API that a lot of hobby anime apps were built on, went offline. My app, MyAnimeDex (a free anime tracker for iOS and Android), used it on almost every screen: search, anime details, seasonal charts, recommendations.

This is how I moved everything to the AniList GraphQL API without touching most of those screens, and the rate-limit bugs I hit on the way.

The trick: keep the old shape, change what's behind it

Screens imported one module, lib/jikan.ts, and used Jikan-shaped objects: mal_id, images.jpg.large_image_url, genres: [{ mal_id, name }] and so on. Rewriting the home screen, anime details, lists, onboarding, the dice picker and the recommendation service to AniList's shape at once would have broken things I couldn't easily test.

Instead lib/jikan.ts kept its exports and types, and started delegating to a new AniList service. A normalizer converts each AniList Media object into the old shape:

const toAnime = (media) => ({
  mal_id: media.idMal || media.id,
  title: media.title.romaji,
  title_english: media.title.english,
  images: { jpg: { large_image_url: media.coverImage.extraLarge } },
  score: media.averageScore ? media.averageScore / 10 : null,
  genres: media.genres.map((name) => ({ name })),
  // ...
});

Two details mattered more than I expected:

  • IDs. Users' lists stored MyAnimeList IDs. AniList exposes them as idMal, but not every entry has one. Every lookup goes idMal first, then the AniList id, and the normalizer writes idMal || id back into mal_id. The name is historical now, but nothing that reads it had to change.
  • Genres. Some old queries filtered by Jikan genre IDs (1 = Action, 4 = Comedy...). AniList filters by genre name, so a small lookup table translates IDs to names at the boundary.

Rate limits will find you

AniList allows roughly 90 requests a minute, and less when the service is under load. My home screen fired a handful of parallel queries; the calendar fired one per day. On a busy day that was enough to hit HTTP 429, retry immediately, hit 429 again and loop.

The fix was a single entry point for every request:

  1. A request queue. Each call reserves the next slot, at least 350 ms after the previous one. Parallel calls from different screens line up instead of bursting.
  2. Respect Retry-After. On HTTP 429 the client waits for the Retry-After header (3.5 s if it's missing) and retries a limited number of times. AniList can also return rate-limit errors inside a 200 GraphQL response, so those are handled the same way.
  3. Cache by key. Calls that pass a cacheKey reuse the result for a while, so navigating back and forth doesn't refetch.
  4. Stale-if-error on disk. Important calls also save their last good response to disk. When the network or AniList is down, the app shows that instead of an empty screen.

After this, the rate-limit loops that had been my most persistent bug stopped.

Things I'd do the same way again

  • One HTTP entry point. Throttling, retries and caching live in one function, so a new screen can't accidentally bypass them.
  • Normalize at the edge. The rest of the app doesn't know which API it talks to. If AniList changes, one file changes.
  • Batch with aliases. GraphQL lets you ask for several media in one request (a0: Media(id: 1) {...} a1: Media(id: 5) {...}). For build scripts that fetch 100 anime, five per request with a pause between them stays well under the limit.

If you're still on Jikan

Start with the facade, not the screens: one module that keeps your current data shape and talks to the new API behind it. Then put every request through one throttled client before you ship. In my case the rate-limit loops were harder to track down than the data mapping.

If you're maintaining a Jikan-based app and need to switch, I'm happy to answer questions in the comments.

This post was written with an AI assistant, based on my app's source code.

來源:DEV Community · dev.to