fluent-wp-client
v2.2.0
Published
Runtime-agnostic TypeScript WordPress REST API client with typed CRUD, auth, abilities, and relation helpers
Maintainers
Readme
fluent-wp-client
Runtime-agnostic TypeScript client for the WordPress REST API.
Works on Node.js, Deno, Bun, and in the browser — using only web-standard APIs (fetch, URL, Blob).
Install
npm install fluent-wp-clientQuick start
import { WordPressClient } from 'fluent-wp-client';
const wp = new WordPressClient({
baseUrl: 'https://your-wordpress-site.com',
});
// Read a list of posts
const posts = await wp.getPosts({ perPage: 10 });
// Read a single post and parse its Gutenberg blocks
const blocks = await wp.getPostBySlug('hello-world').getBlocks();
// Create a draft post (requires auth)
const draft = await wp.createPost({ title: 'Hello', status: 'draft' });Features
- Typed helpers for posts, pages, media, categories, tags, users, comments, and settings
- Generic CPT and taxonomy APIs —
content('books')andterms('genre')work for any registered resource - Gutenberg block parsing — single-post queries expose
.getBlocks()and.getContent() - Auth flexibility — Basic auth (application passwords), JWT, cookie+nonce, prebuilt headers, and per-request signing
- WPAPI-compatible fluent syntax — migrate from
node-wpapiwith minimal changes - WordPress Abilities API — discover and execute registered abilities with optional schema validation
- Standard Schema validation — validator-agnostic root exports; native Zod available from
fluent-wp-client/zod - Relation API —
wp.post('slug').with('author', 'categories').get()
Auth examples
// Basic auth (WordPress application passwords)
const wp = new WordPressClient({
baseUrl: 'https://example.com',
auth: { username: 'admin', password: 'app-password' },
});
// JWT auth
const wp = new WordPressClient({
baseUrl: 'https://example.com',
auth: { token: 'jwt-token' },
});
// Cookie + nonce (browser sessions)
const wp = new WordPressClient({
baseUrl: 'https://example.com',
auth: { nonce: window.wpApiSettings.nonce, credentials: 'include' },
});Documentation
Full documentation lives in the docs/ folder:
- Overview — feature overview and quick start
- Usage guide — all client methods, CRUD patterns, pagination, and error handling
- Authentication — auth strategies and resolver helpers
- Gutenberg content — block parsing and content workflows
- Custom endpoints — custom post types, taxonomies, and plugin namespaces
- Abilities — WordPress Abilities API
- Validation — Standard Schema, Zod, and custom validators
- Migrate from node-wpapi — migration guide
Development
# Start the local WordPress environment
npm run wp:start
# Run the integration test suite
npm test
# Stop the environment
npm run wp:stopTests run against a real WordPress Docker container managed by @wordpress/env. See tests/ for setup details.
License
MIT
