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

wp-headless-client

v1.0.2

Published

Modern, TypeScript-first WordPress REST API client for headless applications

Readme

WP Headless Client

npm version npm downloads License: MIT TypeScript

Modern, TypeScript-first WordPress REST API client for headless applications.

Features

  • TypeScript First - Full type safety with auto-completion
  • Lightweight - Zero dependencies, ~5-10KB bundle size
  • Modern - Uses native fetch API
  • Authentication - Supports JWT, Basic Auth, Application Passwords
  • Framework Agnostic - Works with React, Next.js, Vue, or vanilla JS
  • Pagination - Built-in support for WordPress pagination headers
  • Error Handling - Typed error responses

Installation

npm install wp-headless-client

Quick Start

import { WordPressClient } from 'wp-headless-client';

// Initialize client
const wp = new WordPressClient({
  baseURL: 'https://your-wordpress-site.com',
});

// Fetch posts
const { data: posts } = await wp.getPosts({
  per_page: 10,
  orderby: 'date',
});

console.log(posts);

Authentication

Application Password (Recommended)

const wp = new WordPressClient({
  baseURL: 'https://your-site.com',
  auth: {
    username: 'your-username',
    password: 'xxxx xxxx xxxx xxxx xxxx xxxx', // Application password
  },
});

JWT Token

const wp = new WordPressClient({
  baseURL: 'https://your-site.com',
  auth: {
    token: 'your-jwt-token',
  },
});

Usage Examples

Get Posts with Filters

const { data: posts, headers } = await wp.getPosts({
  per_page: 10,
  page: 1,
  categories: [5, 10],
  orderby: 'date',
  order: 'desc',
  search: 'headless',
});

// Pagination info from headers
const totalPages = parseInt(headers['x-wp-totalpages']);
const totalPosts = parseInt(headers['x-wp-total']);

Get Single Post

const { data: post } = await wp.getPost(123);

console.log(post.title.rendered);
console.log(post.content.rendered);

Create Post

const { data: newPost } = await wp.createPost({
  title: { rendered: 'My New Post' },
  content: { rendered: '<p>Post content</p>' },
  status: 'publish',
});

Update Post

const { data: updated } = await wp.updatePost(123, {
  title: { rendered: 'Updated Title' },
});

Delete Post

// Move to trash
await wp.deletePost(123);

// Permanently delete
await wp.deletePost(123, true);

Configuration Options

interface WPClientConfig {
  baseURL: string;          // WordPress site URL (required)
  auth?: {
    username?: string;      // WordPress username
    password?: string;      // Application password
    token?: string;         // JWT token
  };
  timeout?: number;         // Request timeout in ms (default: 30000)
  headers?: Record<string, string>;  // Custom headers
}

TypeScript Support

All WordPress REST API types are included:

import type { WPPost, WPPostsQuery, WPAPIResponse } from 'wp-headless-client';

const posts: WPPost[] = [];
const query: WPPostsQuery = {
  per_page: 10,
  orderby: 'date',
};

Error Handling

try {
  const { data } = await wp.getPost(999);
} catch (error) {
  console.error('WordPress API Error:', error.message);
}

Roadmap

  • [ ] React hooks (usePost, usePosts, useAuth)
  • [ ] Support for custom post types
  • [ ] Media upload helpers
  • [ ] Caching layer
  • [ ] Request retry logic

Why This Package?

The popular wpapi package (52K+ weekly downloads) hasn't been updated in 5+ years and lacks TypeScript support. This package provides:

  • Modern TypeScript types
  • Native fetch (no axios dependency)
  • Smaller bundle size
  • Active maintenance
  • Better developer experience

Contributing

Contributions welcome! Please open an issue or PR on GitHub.

License

MIT © Sanny Srivastava

Links