Monday, 26 Oct 2026

Exclusive resources and tools for web design and development experts

Explore
BiblioWeb

Biblioweb.es

All About Web Technology

  • Start
  • WordPress
    WordPress
    • All about WordPress26
    • Plugins de WordPress16
    • Desarrollo web y plugins15
    Rendimiento y seguridad
    • Hosting y rendimiento8
    • Ciberseguridad web7
    • Solución de errores5
    Negocio e IA
    • IA y automatización10
    • WooCommerce y tiendas online6
    Lo último
    Restaurant Menu Widget — WordPress Plugin27 Sep 2026JetStudio Bookings — WordPress Plugin27 Sep 2026SC Heatmap — WordPress Plugin27 Sep 2026
    Ver el blog completoHistorial de noticiasAbout usNewsletter semanal
  • Plugins de WordPress
    Fichas de plugins
    • WP Translate Master
    • Cart Tool Kit
    • SC Heatmap
    • JetStudio Bookings
    • Restaurant Menu Widget
    • WP SEO Pro
    • Rank Math SEO in 2026
    • WP Rocket
    • WPCode
    • AI Engine para WordPress
    Comparativas y guías
    • The best SEO plugins for WordPress
    • The best AI plugins for WordPress
    • The best booking plugins for WordPress
    • WordPress multiidioma
    • Cómo crear un formulario de contacto en WordPress
    • Stripe o PayPal
    Por temática
    • Plugins de WordPress16
    • WooCommerce y tiendas online6
    • Desarrollo web y plugins15
    • IA y automatización10
    • Hosting y rendimiento8
    BibliotecaPlugin Library

    Los plugins de WordPress que desarrollamos: qué hace cada uno, cómo se ve en acción y dónde conseguirlo.

    Entrar en la Pluginteca
    Toda la categoría Plugins de WordPressHerramientas gratis
  • Tools
    Herramientas gratis, sin registro y desde el navegador
    Generador de contraseñasContraseñas largas y aleatorias sin salir del navegador.Generador de QRCódigos QR en PNG de alta resolución, sin caducidad.Contador de palabrasPalabras, caracteres y tiempo de lectura en vivo.JSON FormatterFormatea, valida y localiza el error exacto.WebP ConverterPNG, JPG y PDF a WebP para que la web cargue…PDF a WebPCada página del PDF, en una imagen ligera.Comprobador de emailsSintaxis, correos temporales y registros MX.Compresor de vídeoBaja el peso del vídeo sin subirlo a ningún servidor.Vídeo a MP3Extrae el audio de un vídeo en un par de clics.Firmas de emailFirma en HTML lista para Gmail y Outlook.
    También te sirveHerramientas externas que merecen la pena

    DNS Checker, Query Monitor, Local WP y el resto del kit que usamos a diario, con para qué sirve cada una.

    Ver la selección
    Todas las herramientasPlugin LibraryRecíbelas por correo
  • Plugin Library
  • Español
  • English ✓
  • 🇨🇳 中文(简体)
  • Français
  • Deutsch
  • Italiano
Newsletter
  • WordPress
  • Plugins de WordPress
  • WooCommerce
  • IA para WordPress
  • Security
  • Herramientas gratis
  • See everything
BiblioWebBiblioWeb
Font ResizerAa
  • WordPress
  • Plugins
  • WooCommerce
  • Errores
  • Tools
Search
  • Start
  • WordPress
    • All about WordPress
    • WordPress Plugins
    • Web Development and Plugins
    • AI and Web Automation
    • WooCommerce
    • Hosting and Web Performance
    • Cybersecurity and Web Security
    • Web Error Resolution
  • Plugins de WordPress
    • Rank Math SEO
    • AI Engine
    • WP Rocket
    • WPCode
    • WP Translate Master
    • Cart Tool Kit
    • SC Heatmap
    • JetStudio Bookings
    • Restaurant Menu Widget
    • WP SEO Pro
  • Tools
    • Password Generator
    • QR Code Generator
    • Word Counter
    • JSON Formatter
    • Image to WebP Converter
    • Email Checker
    • Video Compressor for Web
    • Email Signature Generator
    • Video to MP3 Converter
    • PDF to WebP Converter
  • Plugin Library
  • Blog
    • Español
    • English ✓
    • 🇨🇳 中文(简体)
    • Français
    • Deutsch
    • Italiano
Síguenos
© 2026 BiblioWeb — All rights reserved.
Cover » Blog » The WordPress REST API: what it is and how to use it
Web Development and Plugins

The WordPress REST API: what it is and how to use it

Adrián Alcalá
Actualizado: 28/09/2026 12:43
By Adrián Alcalá
Share
14 min de lectura
The WordPress REST API: what it is and how to use it
SHARE

Your WordPress is not just a website: it's also a data server. Since version 4.7, the WordPress REST API is integrated into the core and exposes posts, pages, users, media, and taxonomies in JSON format, ready to be read or modified from any external application: a mobile app, an automation script, another website, or a custom control panel. It's the technology that powers the block editor, that thousands of integrations use, and the gateway to what's called "headless" WordPress. And yet, many advanced users have never explored it. In this practical guide, we will see what exactly the WordPress REST API is, how its endpoints are organized, how to authenticate securely with Application Passwords, how to read and create content with real examples (from the browser, with JavaScript, and with PHP), how to create your own endpoints, and what security precautions should be taken. All with functional code that you can try on your own website today.

Índice
What is the WordPress REST API and what is it forMain Endpoints: the API mapAuthentication with Application PasswordsRead and create content: examples with JavaScriptCreate your own endpoints with register_rest_routeSecurity: what to expose and what to protectFrequently Asked QuestionsConclusion

What is the WordPress REST API and what is it for

A REST API is an interface that allows two systems to communicate over HTTP using the classic protocol operations: GET for reading, POST for creating, PUT/PATCH for updating and DELETE for deleting. The response arrives in JSON, a lightweight text format that any language understands. In the case of WordPress, this means that everything you manage from the dashboard (posts, pages, comments, categories, users, media) also has a structured and official "backdoor" for machines.

Real use cases where the WordPress REST API makes a difference:

  • Automation: publish or update content from scripts, spreadsheets, or tools like n8n and Make.
  • Headless WordPress: use WordPress only as a content manager and build the frontend with React, Vue, or Astro.
  • Mobile apps: the official WordPress app works entirely on this API.
  • Website integrations: display the latest articles from one website on another, synchronize catalogs, centralize publishing.
  • Custom dashboards: dashboards that read and write to WordPress without going through wp-admin.

The API is also the basis for modern integrations with artificial intelligence: plugins like AI Engine, which turns your WordPress into an AI agent, they rely on it to expose content to external assistants.

Main Endpoints: the API map

Everything starts with a URL: https://tudominio.com/wp-json/. Open it in the browser and you will see the complete index of available routes. Core endpoints hang from the namespace wp/v2:

Endpoint Content
/wp-json/wp/v2/posts Blog posts
/wp-json/wp/v2/pages Pages
/wp-json/wp/v2/media Media Library
/wp-json/wp/v2/categories Categories
/wp-json/wp/v2/tags Tags
/wp-json/wp/v2/users Users (public data)
/wp-json/wp/v2/comments Comments
/wp-json/wp/v2/search Global search

Each collection endpoint supports very useful query parameters: ?per_page=5 limits results, ?search=wordpress searches, ?categories=12 filters by category, ?orderby=date&order=asc sorts and ?_fields=id,title,link returns only the fields you request, lightening the response. For a specific item, its ID is added: /wp-json/wp/v2/posts/123.

You Might Also Like

Cloud development environments for WordPress
How to install and configure Yoast SEO in WordPress
What is Elementor and how to use it: a getting started guide
What is a child theme in WordPress and how to create it

WordPress JSON responses arrive unformatted, in a single line that is difficult to read. A workflow trick: paste the response into our free JSON formatter and validator and you will have the indented and colored tree to inspect it comfortably.

Pagination: the headers you should know

Collection endpoints return a maximum of 100 items per request (10 by default). To browse large catalogs, the API includes two HTTP headers in each response: X-WP-Total, with the total number of items, and X-WP-TotalPages, with the number of pages available according to your per_page. Simply iterate by adding ?page=2, ?page=3 and so on until the last one is reached. If you request a non-existent page, the API responds with a 400 error with the code rest_post_invalid_page_number, a convenient signal to stop the loop in export or migration scripts.

Authentication with Application Passwords

Reading public content does not require authentication, but creating, editing, or deleting does. Since WordPress 5.6, the integrated and recommended method is Application Passwords (application passwords): app-specific keys, individually revocable, that do not expose your real password.

To create one: go to Users → Profile, scroll down to "Application Passwords", type a descriptive name (for example "Publishing Script") and click create. WordPress will show you a key in the format xxxx xxxx xxxx xxxx xxxx xxxx. Save it in a password manager or an environment variable file, never in the source code.

The key is used with HTTP Basic authentication: username and application password encoded in Base64 in the header Authorization. Essential requirement: the website must be served over HTTPS, because in plain HTTP the credentials would travel exposed.

Quick test from the terminal with curl:

curl -X POST https://tudominio.com/wp-json/wp/v2/posts \
  -u "tu_usuario:xxxx xxxx xxxx xxxx xxxx xxxx" \
  -H "Content-Type: application/json" \
  -d '{"title":"Borrador desde la API","status":"draft"}'

If the response is a JSON with the ID of the new draft, authentication works. Each permission depends on the user's role: an application password from a subscriber will not be able to publish posts.

Read and create content: examples with JavaScript

Let's see the API in action with fetch, just as you would on an external website or application. First, read the latest blog articles (without authentication, public content):

const API = 'https://tudominio.com/wp-json/wp/v2';

async function ultimasEntradas() {
  const res = await fetch(`${API}/posts?per_page=5&_fields=id,title,link,date`);
  if (!res.ok) {
    throw new Error('Error HTTP ' + res.status);
  }
  const posts = await res.json();
  posts.forEach((post) => {
    console.log(`${post.date} — ${post.title.rendered} — ${post.link}`);
  });
}

ultimasEntradas();

And now, create a post by authenticating with an Application Password (this must be executed in a server environment or private script, never in your visitors' browser, because it would expose the key):

const usuario = 'tu_usuario';
const clave   = 'xxxx xxxx xxxx xxxx xxxx xxxx';
const token   = Buffer.from(`${usuario}:${clave}`).toString('base64');

async function crearEntrada() {
  const res = await fetch('https://tudominio.com/wp-json/wp/v2/posts', {
    method: 'POST',
    headers: {
      'Authorization': `Basic ${token}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      title: 'Publicado por la REST API',
      content: '<p>Este contenido lo ha creado un script.</p>',
      status: 'draft',
      categories: [12],
    }),
  });
  const data = await res.json();
  if (!res.ok) {
    throw new Error(data.message || 'Error al crear la entrada');
  }
  console.log('Creada con ID', data.id, '→', data.link);
}

crearEntrada();

Note the detail of title.rendered when reading: the API returns text fields as objects with the variants rendered (final HTML) and, if you are authenticated with editing permissions and add ?context=edit, also raw (original content).

Create your own endpoints with register_rest_route

The core API covers standard content, but the true potential comes when you expose your own data. With register_rest_route() you can create custom routes under your own namespace. Full example: an endpoint that returns basic site statistics, with a validated parameter and permission control:

<?php
add_action( 'rest_api_init', function () {
    register_rest_route( 'biblioweb/v1', '/estadisticas', array(
        'methods'             => 'GET',
        'callback'            => 'biblioweb_api_estadisticas',
        'permission_callback' => '__return_true', // Endpoint público de solo lectura.
        'args'                => array(
            'tipo' => array(
                'default'           => 'post',
                'sanitize_callback' => 'sanitize_key',
                'validate_callback' => function ( $valor ) {
                    return post_type_exists( $valor );
                },
            ),
        ),
    ) );
} );

function biblioweb_api_estadisticas( WP_REST_Request $request ) {
    $tipo     = $request->get_param( 'tipo' );
    $conteo   = wp_count_posts( $tipo );
    $usuarios = count_users();

    return rest_ensure_response( array(
        'tipo'        => $tipo,
        'publicados'  => (int) $conteo->publish,
        'borradores'  => (int) $conteo->draft,
        'usuarios'    => (int) $usuarios['total_users'],
        'generado_en' => current_time( 'mysql' ),
    ) );
}

After saving this code (in a plugin or snippet), your new endpoint responds at https://tudominio.com/wp-json/biblioweb/v1/estadisticas?tipo=page. Three golden rules: always use your own versioned namespace (biblioweb/v1), define permission_callback explicitly (it is mandatory since WordPress 5.5; for private endpoints use a check like current_user_can( 'edit_posts' )) and validates each input parameter. The complete reference is in the official WordPress REST API handbook.

Security: what to expose and what to protect

The WordPress REST API is secure by design (it only exposes what is already public and requires permissions to write), but it is advisable to adjust some details:

  • User enumeration: the endpoint /wp/v2/users lists authors with published content, which makes it easier for an attacker to know valid usernames. Many security plugins restrict it; it can also be filtered by code to require authentication.
  • HTTPS mandatory: without an SSL certificate, Application Passwords travel in plain text. There is no reasonable exception to this rule.
  • Principle of least privilege: create application passwords with a user whose role has only the permissions the integration needs, and revoke them when they are no longer used.
  • Don't disable the API brutally: the block editor and many plugins depend on it. If you want to limit it, require authentication with the filter rest_authentication_errors instead of blocking it completely.
  • Limit the surface: public custom endpoints should only return data that you don't mind being visible to anyone.

These precautions fit within a general hardening strategy; if you want to review it, we have a guide with tricks to strengthen your WordPress security.

Frequently Asked Questions

Is the WordPress REST API active on my website?

Almost certainly, yes: it comes activated by default since WordPress 4.7 (2016). Check it by visiting tudominio.com/wp-json/: if you see a JSON with your site name and the list of routes, it is operational. If it returns a 404, check your permalinks or any security plugin that might be blocking it.

Is it dangerous to have the API activated?

No more than having the website published. The read API only exposes content that is already public on your website, and every write operation requires authentication and permissions. The two sensible adjustments are to restrict the user list and ensure everything is served over HTTPS. Completely disabling it usually causes more problems than it prevents.

Can I use the API with custom post types and custom fields?

Yes. Custom post types appear in the API if they were registered with show_in_rest => true, and get their own endpoint (for example /wp/v2/proyecto). Custom fields are exposed with register_post_meta() also checking show_in_rest, or with the field meta of the post itself if the plugin that creates them supports it.

What is the difference between the REST API and WPGraphQL?

The REST API is the core standard: each data type has its endpoint and responses have a fixed structure. GraphQL (via the WPGraphQL plugin) allows you to request exactly the fields you need in a single query, which is popular in complex headless projects. For automations, integrations, and most projects, the REST API is simpler, requires no plugins, and is officially supported.

Conclusion

The WordPress REST API turns your website into a programmable platform: a clear index of endpoints under /wp-json/wp/v2/, integrated authentication with Application Passwords over HTTPS and the possibility of extending the map with custom routes using register_rest_route(). With what you've seen in this guide, you can read public content from any application, publish and edit using authenticated scripts, expose custom data with validation and permissions, and do so with appropriate security precautions. The best way to internalize it is practical: open tudominio.com/wp-json/wp/v2/posts?per_page=3 in the browser, pass the response through a JSON formatter to understand its structure, create your first Application Password and launch a draft from curl. In fifteen minutes you will have crossed the door that separates using WordPress from programming with WordPress.

Share This Article
Email Copiar enlace Print
ByAdrián Alcalá
Síguele:
Adrián Alcalá es desarrollador WordPress y consultor SEO, autor del plugin WP Translate y creador de BiblioWeb. Desde aquí comparte guías, tutoriales y herramientas gratuitas para quienes crean, optimizan y posicionan páginas web. Lleva años ayudando a negocios de toda España a sacar el máximo partido a WordPress, y todo lo que publica está probado en proyectos reales.
Previous Article Custom Post Types in WordPress: complete guide Custom Post Types in WordPress: complete guide
Next Article The best cache plugins for WordPress The best cache plugins for WordPress
Ilustración del plugin Restaurant Menu Widget: carta de restaurante con platos y precios editables en Elementor
Restaurant Menu Widget — WordPress Plugin
WordPress Plugins
Ilustración del plugin JetStudio Bookings: formulario de citas por pasos con calendario y bandeja de solicitudes
JetStudio Bookings — WordPress Plugin
WordPress Plugins
Ilustración del plugin SC Heatmap: mapa de calor de clics y scroll sobre una web, con los datos en tu servidor
SC Heatmap — WordPress Plugin
WordPress Plugins
Accesibilidad web en WordPress con IA
Accesibilidad web en WordPress: auditarla con IA en una tarde
AI & Web Automation

También te puede interesar

WordPress Shortcodes: what they are and how to create them
Web Development and Plugins

WordPress Shortcodes: what they are and how to create your own

08/08/2026
WordPress Plugins - Don't start without them The 5 Essential WordPress Plugins every beginner needs for a top-notch website
Web Development and Plugins

The 5 essential WordPress plugins for beginners

28/09/2026
Custom Post Types in WordPress: complete guide
Web Development and Plugins

Custom Post Types in WordPress: complete guide

08/08/2026
Internal tools for web agencies
Web Development and Plugins

Internal tools for web agencies: when and how to create them

08/08/2026
Show More
  • Temas:
  • WordPress
  • WordPress Plugins
  • Web Development and Plugins
  • AI & Web Automation
  • Web Hosting & Performance
  • Cybersecurity and Web Security
  • WooCommerce
  • Troubleshooting web errors
BiblioWeb

Biblioweb.es

Web Technology News

Information you can trust: practical web technology guides and solutions — WordPress, plugins, cybersecurity, hosting, performance, and error troubleshooting.

RSS

Enlaces de interés

  • About us
  • Contact
  • Free tools
  • Plugin Library

Recibe nuestras nuevas guías de WordPress en tu correo. Suscríbete a la newsletter.

Legal

  • Legal Notice
  • Terms and Conditions
  • Cookies Policy
  • Privacy Policy

Últimas novedades

Ilustración del plugin Restaurant Menu Widget: carta de restaurante con platos y precios editables en Elementor

Restaurant Menu Widget — WordPress Plugin

27/09/2026
Continue reading
Ilustración del plugin JetStudio Bookings: formulario de citas por pasos con calendario y bandeja de solicitudes

JetStudio Bookings — WordPress Plugin

27/09/2026
Continue reading

© 2026 BiblioWeb — All rights reserved.

Gestionar consentimiento
Utilizamos tecnologías como las cookies para almacenar y/o acceder a la información del dispositivo. Lo hacemos para mejorar la experiencia de navegación y para mostrar anuncios (no) personalizados. El consentimiento a estas tecnologías nos permitirá procesar datos como el comportamiento de navegación o los ID's únicos en este sitio. No consentir o retirar el consentimiento, puede afectar negativamente a ciertas características y funciones.
Funcional Always active
El almacenamiento o acceso técnico es estrictamente necesario para el propósito legítimo de permitir el uso de un servicio específico explícitamente solicitado por el abonado o usuario, o con el único propósito de llevar a cabo la transmisión de una comunicación a través de una red de comunicaciones electrónicas.
Preferences
El almacenamiento o acceso técnico es necesario para la finalidad legítima de almacenar preferencias no solicitadas por el abonado o usuario.
Estadísticas
El almacenamiento o acceso técnico que es utilizado exclusivamente con fines estadísticos. El almacenamiento o acceso técnico que se utiliza exclusivamente con fines estadísticos anónimos. Sin un requerimiento, el cumplimiento voluntario por parte de tu proveedor de servicios de Internet, o los registros adicionales de un tercero, la información almacenada o recuperada sólo para este propósito no se puede utilizar para identificarte.
Marketing
El almacenamiento o acceso técnico es necesario para crear perfiles de usuario para enviar publicidad, o para rastrear al usuario en una web o en varias web con fines de marketing similares.
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
Ver preferencias
  • {title}
  • {title}
  • {title}
Accede a BiblioWeb
Usuario o correo electrónico
Contraseña

¿Has olvidado tu contraseña?