The WordPress REST API lets you use WordPress as a content source without its usual website design. This means you can build your website or app separately and get content from WordPress easily.
Why WordPress REST API enables headless usage
GET /wp-json/wp/v2/posts
// Example: Fetch posts from WordPress REST API endpointThe REST API uses URLs to get data in JSON format.
You can use HTTP methods like GET, POST, PUT, DELETE to interact with WordPress data.
GET https://example.com/wp-json/wp/v2/posts
GET https://example.com/wp-json/wp/v2/pages/42POST https://example.com/wp-json/wp/v2/posts
{
"title": "New Post",
"content": "This is the post content."
}This JavaScript code fetches posts from the WordPress REST API and prints each post's title and content in the console.
fetch('https://example.com/wp-json/wp/v2/posts') .then(response => response.json()) .then(posts => { posts.forEach(post => { console.log(`Title: ${post.title.rendered}`); console.log(`Content: ${post.content.rendered}`); console.log('---'); }); }) .catch(error => console.error('Error fetching posts:', error));
The REST API returns data in JSON, which is easy to use in many programming languages.
Using the REST API separates content management from how the content is shown, giving more design freedom.
Authentication is needed for creating or editing content via the API.
The WordPress REST API lets you get and manage content without using WordPress themes.
This enables building websites or apps with any technology while still using WordPress as the content backend.
It makes WordPress flexible and modern for many types of projects.