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

@codewheel/jsonapi-frontend-client

v1.0.7

Published

TypeScript client helpers for Drupal drupal/jsonapi_frontend

Readme

@codewheel/jsonapi-frontend-client

TypeScript client helpers for Drupal drupal/jsonapi_frontend.

This package is optional. You can always call /jsonapi/resolve directly with fetch().

Install

npm i @codewheel/jsonapi-frontend-client

Usage

Set DRUPAL_BASE_URL (must be a full http(s):// URL), then:

import { resolvePath, fetchJsonApi } from "@codewheel/jsonapi-frontend-client"

const resolved = await resolvePath("/about-us")
if (resolved.resolved && resolved.kind === "entity") {
  const doc = await fetchJsonApi(resolved.jsonapi_url)
  console.log(doc.data)
}

Layout Builder (optional)

If you install the jsonapi_frontend_layout add-on module, you can resolve a path and (when applicable) receive a normalized Layout Builder tree:

import { resolvePathWithLayout, fetchJsonApi } from "@codewheel/jsonapi-frontend-client"

const resolved = await resolvePathWithLayout("/about-us")
if (resolved.resolved && resolved.kind === "entity") {
  const doc = await fetchJsonApi(resolved.jsonapi_url)
  if (resolved.layout) {
    console.log(resolved.layout.sections)
  }
}

Astro / Vite (import.meta.env)

import { resolvePath, fetchJsonApi } from "@codewheel/jsonapi-frontend-client"

const baseUrl = import.meta.env.DRUPAL_BASE_URL

const resolved = await resolvePath("/about-us", { baseUrl })
if (resolved.resolved && resolved.kind === "entity") {
  const doc = await fetchJsonApi(resolved.jsonapi_url, { baseUrl })
}

Authentication (optional)

Keep credentials server-side. Pass headers via options.headers:

import { resolvePath } from "@codewheel/jsonapi-frontend-client"

const baseUrl = process.env.DRUPAL_BASE_URL!
const auth = "Basic " + Buffer.from(`${process.env.DRUPAL_BASIC_USERNAME}:${process.env.DRUPAL_BASIC_PASSWORD}`).toString("base64")

await resolvePath("/about-us", {
  baseUrl,
  headers: { Authorization: auth },
})
import { resolvePath } from "@codewheel/jsonapi-frontend-client"

await resolvePath("/about-us", {
  headers: { Authorization: `Bearer ${process.env.DRUPAL_JWT_TOKEN}` },
})

Caching note (Next.js / SSR)

If you pass Authorization (or Cookie) headers, this client defaults to cache: "no-store" unless you explicitly set options.init.cache.

Static builds (SSG) routes feed (optional)

If you enable the secret-protected routes feed in Drupal (/jsonapi/routes), you can fetch a complete build-time list of headless paths by following links.next:

import { collectRoutes } from "@codewheel/jsonapi-frontend-client"

const baseUrl = process.env.DRUPAL_BASE_URL!
const secret = process.env.ROUTES_FEED_SECRET!

const routes = await collectRoutes({ baseUrl, secret })
const paths = routes.map((r) => r.path)

Keep ROUTES_FEED_SECRET server-side only (build environment variables). Do not expose it to browsers.

Menus (optional)

If you install the jsonapi_frontend_menu add-on module, you can fetch a ready-to-render tree:

import { fetchMenu } from "@codewheel/jsonapi-frontend-client"

const menu = await fetchMenu("main", { path: "/about-us" })
console.log(menu.data)

Query building (optional)

This client doesn’t require a query builder, but drupal-jsonapi-params works well:

import { DrupalJsonApiParams } from "drupal-jsonapi-params"
import { fetchJsonApi } from "@codewheel/jsonapi-frontend-client"

const baseUrl = process.env.DRUPAL_BASE_URL!

const params = new DrupalJsonApiParams()
  .addFilter("status", "1")
  .addFields("node--article", ["title", "path", "body"])

const url = `/jsonapi/node/article?${params.getQueryString()}`
await fetchJsonApi(url, { baseUrl })

URL safety (recommended)

By default, fetchJsonApi() and fetchView() refuse to fetch absolute URLs on a different origin than your DRUPAL_BASE_URL (to avoid accidental SSRF in server environments).

If you intentionally need to fetch a cross-origin absolute URL, pass allowExternalUrls: true:

import { fetchJsonApi } from "@codewheel/jsonapi-frontend-client"

await fetchJsonApi("https://cms.example.com/jsonapi/node/page/...", {
  allowExternalUrls: true,
})