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

@itsmrtr/strapi-next-fetch

v1.0.0

Published

Minimal Strapi REST API client for Next.js App Router with built-in cache support

Downloads

113

Readme

strapi-next-fetch

Minimal Strapi REST API client for Next.js App Router with built-in ISR cache support.

Handles auth headers, query string serialization for nested params (filters, populate, pagination), and Next.js fetch cache options (revalidate, force-cache, no-store).

Why this package?

Strapi has an official JavaScript SDK, but I didn't know about it when I started integrating Strapi into my projects — so I built my own fetch logic from scratch. Over time it became a consistent pattern across projects, so I extracted it into a package.

It's intentionally focused on Next.js App Router and its fetch cache model (revalidate, force-cache, no-store), which is my default stack. If that matches yours, this might save you some boilerplate.

If you prefer the official route, Strapi's SDK is always an option.

Install

# npm
npm install @itsmrtr/strapi-next-fetch

# pnpm
pnpm add @itsmrtr/strapi-next-fetch

# yarn
yarn add @itsmrtr/strapi-next-fetch

Setup

Create a single client instance and reuse it across your project:

// lib/strapi.js
import { createStrapiClient } from "@itsmrtr/strapi-next-fetch";

const strapi = createStrapiClient({
  url: process.env.STRAPI_API_URL,
  token: process.env.STRAPI_API_TOKEN,
});

export default strapi;

Usage

Basic fetch

import strapi from "@/lib/strapi";

const data = await strapi.fetch("/api/articles");

With fields and populate

const data = await strapi.fetch("/api/articles", {
  fields: ["title", "slug", "date"],
  populate: {
    cover: { fields: ["url"] },
    category: { fields: ["title", "slug"] },
  },
});

With filters and pagination

const data = await strapi.fetch("/api/articles", {
  filters: {
    featured: { $eq: true },
    podcast: { $ne: true },
  },
  pagination: { page: 1, pageSize: 9 },
  sort: ["date:desc"],
});

ISR with revalidate (Next.js App Router)

// Revalidate every 15 minutes
const data = await strapi.fetch(
  "/api/articles",
  { sort: ["date:desc"] },
  { revalidate: 900 },
);

No cache (drafts, live previews)

const data = await strapi.fetch(
  "/api/articles",
  { filters: { slug: { $eq: slug } } },
  { cache: "no-store" },
);

Daily cache (static content that rarely changes)

const data = await strapi.fetch(
  "/api/categories",
  { fields: ["title", "slug"], sort: ["title:asc"] },
  { revalidate: 86400 },
);

Draft mode (Strapi v5)

const data = await strapi.fetch(
  "/api/articles",
  {
    filters: { slug: { $eq: slug } },
    status: "draft",
  },
  { cache: "no-store" },
);

Build URL without fetching

const url = strapi.buildUrl("/api/articles", {
  filters: { slug: { $eq: "my-article" } },
});
// https://your-strapi.com/api/articles?filters[slug][$eq]=my-article

Practical pattern: query functions per project

Keep your query functions in your own project, using the client:

// lib/queries/articles.js
import strapi from "@/lib/strapi";

export async function getLatestPosts({ page = 1, pageSize = 9 } = {}) {
  return strapi.fetch(
    "/api/articles",
    {
      fields: ["title", "slug", "date"],
      populate: {
        cover: { fields: ["url"] },
        category: { fields: ["title", "slug"] },
      },
      pagination: { page, pageSize },
      sort: ["date:desc"],
    },
    { revalidate: 900 },
  );
}

export async function getSingleArticle(slug) {
  return strapi.fetch(
    "/api/articles",
    {
      fields: ["title", "date", "content", "slug"],
      populate: {
        cover: { fields: ["url", "caption"] },
        category: { fields: ["title", "slug"] },
      },
      filters: { slug: { $eq: slug } },
    },
    { revalidate: 900 },
  );
}

Environment variables

STRAPI_API_URL=https://your-strapi-instance.com
STRAPI_API_TOKEN=your-api-token

Compatibility

  • Next.js 14+ (App Router)
  • Strapi v4 and v5
  • Node.js 18+

License

MIT