Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk4 min

How to Use the WordPress REST API to Build a Headless Site

Use WordPress as a content backend and a separate front end as the renderer. Learn route discovery, JSON requests, pagination, authentication, and browser security.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To build a headless site with WordPress, keep WordPress as the content backend and have a separate front end request its REST API for JSON. Start by discovering the routes available on your site, fetch public content with HTTP GET requests, and handle collection pagination. For private data or write operations, authenticate the request and ensure the WordPress user has the necessary capability.

What the WordPress REST API does in a headless site

The WordPress REST API lets another application work with a WordPress site by sending and receiving JSON over HTTP. In a headless setup, WordPress manages content while a separate application renders the public-facing pages. WordPress describes a separate front-end experience as a supported use case; the API also underpins the Block Editor. As WordPress Developer Resources puts it, “The WordPress REST API provides an interface for applications to interact with your WordPress site by sending and receiving data as JSON (JavaScript Object Notation) objects.” WordPress REST API Handbook

As an Amazon Associate I earn from qualifying purchases.

“Headless” does not require a particular JavaScript framework or change the API itself. It describes the separation between content management and presentation. The front end makes HTTP requests; WordPress responds with the requested resource data, subject to the site’s configuration and content visibility.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to find your site’s API routes

The REST API is distributed: each WordPress site exposes its own API index, which describes available routes and supported methods. With pretty permalinks enabled, open https://example.com/wp-json/, replacing the domain with your site’s address. If pretty permalinks are not enabled, WordPress can receive the REST route through the rest_route query parameter. The site’s base path can vary. WordPress Routes and Endpoints

Common core resource routes include:

  • /wp/v2/posts for posts
  • /wp/v2/pages for pages
  • /wp/v2/media for media
  • /wp/v2/categories for categories
  • /wp/v2/search for search

These are core routes, not a guarantee that every site exposes exactly the same resources or data. Plugins and site configuration may add routes or affect what is available. The API index and REST API reference are the place to check the resources on a specific site. WordPress describes the API as individually available on sites that support it.

How to request and render WordPress content

A route identifies a resource path; an endpoint is the operation available at that route for a particular HTTP method. The usual conventions are GET to read, POST to create, PUT to update, and DELETE to delete. Requests use ordinary HTTP and successful responses contain JSON. WordPress Requests

For example, this command requests the posts collection from a site using pretty permalinks:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl https://example.com/wp-json/wp/v2/posts

This is an illustrative public read request. The response can differ with site configuration, plugins, and whether content is public. In a front end, the application uses returned resource fields to render its own pages. WordPress also provides ._links and, where requested and available, ._embedded data for following or including related resources. The exact relationship fields depend on the resource and request. WordPress Using the REST API

How to get a collection’s posts and paginate results

Collection responses are paginated rather than returning an unlimited number of records at once. Use per_page to choose a page size from 1 to 100, page to select a page, and offset to start at a specified position. For example, to request 20 posts from the second page:

/wp-json/wp/v2/posts?per_page=20&page=2

The response headers X-WP-Total and X-WP-TotalPages report the number of matching records and the total number of pages. A client that needs the entire collection must make multiple requests, using the page count to know when to stop. Large queries can affect site performance, so avoid fetching a full library when the front end only needs a subset. WordPress Pagination

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Which authentication method should you use?

Public content is generally readable without authentication. When an operation requires a logged-in identity or changes data, the request must use a supported authentication method, and the WordPress user still needs the capability required for that operation. Choose the method based on where the request runs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Request context WordPress method Key constraint
Logged-in user making a same-site request WordPress cookies and a REST nonce The user must be logged in; action requests need a nonce, commonly sent in X-WP-Nonce.
External server-side application Application Password over HTTPS using Basic Authentication Keep the credential confidential; the WordPress user must have the capability needed for the operation.

Same-site requests from a logged-in user

Cookie authentication is the standard approach for a request made within WordPress while a user is logged in. Requests that perform actions need a REST nonce, commonly sent in the X-WP-Nonce header. Without the nonce, WordPress treats the request as unauthenticated. WordPress documents that “The API uses nonces with the action set to wp_rest.” WordPress Authentication

Requests from an external server

For an external server-side application that needs protected data or write access, WordPress documents Application Passwords sent over HTTPS using Basic Authentication. Application Passwords were introduced in WordPress 5.6. Use an appropriately permissioned WordPress user and store its password on the server, not in code delivered to a browser. Browser users can inspect client-side code and requests, so a secret embedded there is not confidential. Authentication does not grant more access than the associated WordPress user’s capabilities allow. WordPress Authentication

What public browser access and CORS mean for security

CORS controls whether a browser permits front-end code from one origin to read a response from another; it is not authorization. WordPress does not verify the incoming Origin header for REST API requests, so public endpoints may be requested from any site. A public endpoint should therefore be treated as public data, not as protected merely because the front end is hosted elsewhere. WordPress REST API Frequently Asked Questions

For cookie-authenticated requests, WordPress uses nonces to address cross-site request forgery (CSRF). CORS headers can be customized when a site needs stricter browser-origin behavior, but CORS does not replace authentication, nonce checks, or capability checks. Disabling the REST API can also interfere with WordPress Admin functionality; if access needs to be restricted, requiring authentication is preferable to turning the API off entirely. WordPress REST API Frequently Asked Questions

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.