Does Fastify Work With WordPress?

Works With WorkaroundsLast verified: 2026-02-26

Fastify and WordPress don't integrate directly, but you can use Fastify as a headless API layer or proxy in front of WordPress.

Quick Facts

Compatibility
workaround
Setup Difficulty
Moderate
Official Integration
No — community maintained
Confidence
medium
Minimum Versions
Fastify: 4.0.0
WordPress: 5.0

How Fastify Works With WordPress

Fastify and WordPress operate in fundamentally different ecosystems—WordPress is PHP-based while Fastify is Node.js. They don't share a native integration layer. However, developers commonly use Fastify as a headless proxy or API gateway that communicates with WordPress via REST API calls, WP-CLI, or direct database connections. This architecture decouples your frontend from WordPress, allowing you to build modern SPAs or mobile apps while keeping WordPress as your content management backend. You'll make HTTP requests from Fastify to WordPress's REST API endpoints, handle caching strategies, and manage authentication separately. Another approach is using Fastify to serve WordPress content through a Node.js runtime, though this requires significant custom work to port WordPress logic or embed PHP execution, making it impractical. The most viable pattern is treating WordPress as a headless CMS where Fastify becomes your application server, consuming WordPress data programmatically. This gives you Fastify's performance benefits while retaining WordPress's editorial interface and plugin ecosystem.

Best Use Cases

Building a high-performance frontend decoupled from WordPress, using Fastify to aggregate WordPress REST API calls with caching
Creating a mobile app backend that fetches content from WordPress but implements custom business logic in Fastify
Implementing a static site generator that uses Fastify to orchestrate WordPress content export and transformation
Building a real-time content dashboard using Fastify WebSockets that subscribes to WordPress post updates via webhooks

Fastify Proxy to WordPress REST API

bash
npm install fastify node-fetch
typescript
import Fastify from 'fastify';

const fastify = Fastify({ logger: true });
const WORDPRESS_URL = 'https://yourwordpress.com';

fastify.get('/api/posts', async (request, reply) => {
  try {
    const response = await fetch(
      `${WORDPRESS_URL}/wp-json/wp/v2/posts?per_page=10`
    );
    const posts = await response.json();
    
    // Add caching headers
    reply.header('Cache-Control', 'public, max-age=3600');
    return posts;
  } catch (error) {
    reply.code(500).send({ error: 'Failed to fetch posts' });
  }
});

fastify.listen({ port: 3000 }, (err) => {
  if (err) fastify.log.error(err);
});

Known Issues & Gotchas

warning

WordPress REST API rate limiting and performance under high load from Fastify requests

Fix: Implement request caching in Fastify using Redis or in-memory stores; use conditional requests with ETag headers; consider increasing PHP-FPM workers on WordPress host

warning

Authentication complexity—managing JWT tokens for Fastify while WordPress uses session-based auth

Fix: Use WordPress JWT Authentication plugin, implement your own token system in Fastify, or use OAuth2 bridges between the two systems

info

CORS issues when Fastify frontend calls WordPress REST API from browser

Fix: Configure WordPress to allow CORS headers, or route API calls through Fastify proxy instead of directly to WordPress

warning

WordPress plugins may not work with headless setup if they rely on admin UI or hooks

Fix: Use plugins designed for headless WordPress (like ACF Pro); implement custom endpoints for plugin functionality via Fastify

Alternatives

  • Next.js with WordPress REST API—provides built-in SSG/ISR for WordPress content with better React integration
  • Gatsby + WordPress—purpose-built static site generation with WordPress as headless CMS
  • Strapi (headless CMS) + Fastify—both Node.js, more seamless integration than WordPress

Resources

Related Compatibility Guides

Explore more compatibility guides