npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

next-axis

v0.0.6

Published

[![npm](https://img.shields.io/npm/v/next-axis?color=%2300b894&label=next-axis)](https://www.npmjs.com/package/next-axis) [![size](https://img.shields.io/bundlephobia/minzip/next-axis)](https://bundlephobia.com/package/next-axis) ![types](https://img.shie

Readme

next-axis — Next.js-native fetch with Axios-level DX

npm size types deps license

Axios DX without losing Next.js caching. A tiny, zero-dependency HTTP client built on platform fetch that preserves next: { revalidate, tags }, request memoization, and Edge compatibility—while giving you the ergonomics you actually want.


Why this exists

You love Next.js RSC, Server Actions, ISR, tag revalidation… but real apps still call external APIs.

  • Use Axios and you opt out of Next’s server fetch cache/memoization and tag revalidation.
  • Use native fetch and you’re stuck sprinkling if (!res.ok) throw … everywhere, wiring AbortController by hand, and duplicating error handling.

next-axis is a purpose-built, Next-aware wrapper that keeps platform fetch semantics intact and adds a thin layer of DX:

  • Axios-style methods: .get/.post/.put/.patch/.delete/.head/.options
  • Clean errors: auto-reject on non-2xx with error.response.data
  • Interceptors: request & response (auth headers, logging, metrics)
  • Base URL helpers
  • Timeout via AbortController
  • 100% Edge/Workers safe, zero dependencies
  • Full RequestInit pass-through (including next: { revalidate, tags }, cache, signal, credentials)

Not “just another wrapper.” It’s designed specifically for Next.js server/RSC/Route Handlers where fetch is the framework boundary.


Install

npm i next-axis
# or
pnpm add next-axis
# or
yarn add next-axis

Quick start

import http from "next-axis";

// 1) Optional: set a base URL
http.setBaseURL(process.env.NEXT_PUBLIC_API_URL!);

// 2) Minimal auth & cache discipline
http.interceptors.request.use((cfg) => {
  const m = (cfg.method ?? "GET").toUpperCase();
  if (m !== "GET") {
    cfg.withCredentials = true; // cookie auth
    (cfg.headers as any) = {
      ...(cfg.headers ?? {}),
      "X-CSRF-Token": getCsrfToken(),
    };
    cfg.cache = "no-store"; // never cache mutations
  }
  return cfg;
});

// 3) Call it — resolves to `data`
const posts = await http.get<Post[]>("/posts", {
  next: { revalidate: 300, tags: ["posts"] }, // ✅ Next caching + tags preserved
});

Error handling (Axios-style)

import type { HttpError } from "next-axis";

try {
  await http.get("/missing");
} catch (e) {
  const err = e as HttpError;
  console.log(err.status);           // e.g., 404
  console.log(err.response?.data);   // parsed body if JSON/text
}

Route Handler example (server caching + invalidation)

// app/api/posts/route.ts
import http from "next-axis";

export async function GET() {
  const posts = await http.get<Post[]>("https://api.example.com/posts", {
    next: { revalidate: 300, tags: ["posts"] },
  });
  return Response.json(posts);
}

Later, invalidate everywhere tagged "posts":

// app/api/revalidate/route.ts
import { revalidateTag } from "next/cache";

export async function POST() {
  revalidateTag("posts");
  return Response.json({ ok: true });
}

Why pick next-axis over other clients?

| Concern | next-axis | Axios | Ky / ofetch / wretch | | ----------------------------------------------------- | ------------------------------ | ---------------------- | ------------------------------------------------ | | Next server cache (revalidate, tags, memoization) | ✅ Preserved (pass-through) | ❌ Not integrated | ✅ Possible if you forward next (often untyped) | | Edge runtime (no Node APIs) | ✅ | ⚠️ Needs fetch adapter | ✅ | | Errors (auto throw + response.data) | ✅ | ✅ | ✅ (varies per lib) | | Interceptors | ✅ | ✅ | ✅ (hooks/middlewares) | | Size / deps | Zero deps, tiny | Heavier | Small | | DX focus | Axios-style | Axios | Different APIs |

next-axis is the sweet spot if your priority is Next features first, Axios-level DX second.


API

Methods (all resolve to data)

http.get<T>(url, config?)
http.post<T, B>(url, body?, config?)
http.put<T, B>(url, body?, config?)
http.patch<T, B>(url, body?, config?)
http.delete<T>(url, config?)
http.head<T>(url, config?)
http.options<T>(url, config?)
http.request<T>(config) // { url, method, ... }

Configuration (TypeScript)

export type NextCache = { revalidate?: number | false; tags?: string[] };

export type RequestConfig<D = any> = RequestInit & {
  url?: string;
  method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
  baseURL?: string;
  headers?: HeadersInit;
  data?: D;           // auto-JSON if plain object
  timeout?: number;   // ms, AbortController
  withCredentials?: boolean; // → credentials:'include'
  next?: NextCache;   // passed straight to fetch (server only)
};

Interceptors

// Request (FIFO)
const reqId = http.interceptors.request.use((cfg) => {
  // mutate cfg: add Authorization, trace headers, etc.
  return cfg;
});

// Response (FIFO)
const resId = http.interceptors.response.use((resp) => {
  // inspect/transform resp if needed; must return it
  return resp;
});

// Remove later
http.interceptors.request.eject(reqId);
http.interceptors.response.eject(resId);

Runtime helpers

http.setBaseURL("https://api.example.com");
http.setHeader("X-App", "my-app");
http.removeHeader("X-App");

Best practices (Next.js)

  • Cache only idempotent GETs. Use next: { revalidate: N, tags: [...] } or cache: 'force-cache'.
  • Never cache per-user data. For authenticated/user-scoped responses, set cache: 'no-store' (or revalidate: 0).
  • Keep GET headers stable. Don’t add non-deterministic headers (timestamps, random IDs) in request interceptors for cached requests.
  • Client components: next options are ignored in the browser—server caching lives on the server.

FAQ

Why not just Axios with the fetch adapter? You still won’t get Next’s server fetch features (revalidate/tags/memoization). next-axis embraces platform fetch to keep those benefits.

How is this different from Ky/ofetch? Those are great! next-axis is laser-focused on Axios-style DX + explicit Next cache support with zero extra defaults that might change cache keys. If you already use Ky/ofetch, make sure you forward next and avoid mutating GET headers.

Upload/download progress? Not included (to stay tiny). If you need progress, add a browser-only XHR upload helper or a Node streaming path for downloads.


Install size & runtime

  • Zero dependencies
  • Works in Node 18+, modern browsers, and Next.js Edge/Node runtimes.

License

MIT © Kehinde Oke