WordPress provides various lists of Rest API endpoints.
They are used in various places.
In this article, we are going to see:
- What are the Rest API endpoints?
- What is the use of Rest API endpoints?
- How to use Rest API endpoints?
- How to see your website Rest API endpoints?
- WordPress Rest API Namespace
- List of Default Endpoints
- How to show the Rest API data?
- List of All Default Endpoints
- Frequently Asked Questions for Rest API
- What is a REST API endpoint in WordPress?
- What are the default endpoints provided by the WordPress REST API?
- How can I use the WordPress REST API to retrieve data from my site?
- Can I modify the default endpoints provided by the WordPress REST API?
- Are there any security concerns I should be aware of when using the WordPress REST API?
What are the Rest API endpoints? What are the Rest API endpoints?
Rest API endpoints are the way to access your WordPress website data outside your WordPress website.
What is the use of Rest API endpoints? What is the use of Rest API endpoints?
Suppose, You have to build an eCommerce website, Where you have used WooCommmerce and added multiple products.
Now, Suppose you want to build your eCommerce website mobile app then the Rest API endpoints allow accessing your website data.
So, You can manage products from your website which are accessible on the website itself and in the mobile app as well.
How to use Rest API endpoints? How to use Rest API endpoints?
In WordPress you can access the Rest API endpoints by visiting the URL:
/wp-json/
E.g. My website is https://maheshwaghmare.com/
So, I can see my Rest API endpoints at:
https://maheshwaghmare.com/wp-json/
How to see your website Rest API endpoints? How to see your website Rest API endpoints?
Open the browser and visit:
https://example.com/wp-json/
Note: Here, I have used example.com. YOu can change it with your own website domain name. You can also use the localhost if you working local by flywheel or XAMPP.
WordPress Rest API Namespace WordPress Rest API Namespace
WordPress is amazing. It allows the developer to add custom Rest API endpoints as per requirement.
Each RestAPI endpoint is available with the namespaces.
What are namespaces?
Namespaces are simply prefixed paths.
WordPress uses the namespaces /wp/v2/
to register all the endpoints.
E.g.
https://maheshwaghmare.com/wp-json/wp/v2/
Here,
- https://maheshwaghmare.com/wp-json/ – This is a Rest API base URL.
- /wp/v2/ – This is a namespace reserve to the WordPress default endpoints.
List of Default Endpoints List of Default Endpoints
Now, As we see in the above section when we visit the URL:
https://maheshwaghmare.com/wp-json/wp/v2/
We’ll see all the default list of Rest API endpoints.
See the categorized list of all the endpoints.
Posts Posts
Below is the list of all post’s endpoints:
/wp/v2/posts: {}, /wp/v2/posts/(?P<id>[\d]+): {}, /wp/v2/posts/(?P<parent>[\d]+)/revisions: {}, /wp/v2/posts/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+): {}, /wp/v2/posts/(?P<id>[\d]+)/autosaves: {}, /wp/v2/posts/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+): {},
With the help of these endpoints, you’ll access the WordPress posts outside your WordPress website.
E.g.
Display the list of all WordPress posts with Rest API Display the list of all WordPress posts with Rest API
We can visit the URL:
https://maheshwaghmare.com/wp-json/wp/v2/posts/
By visiting this URL, we’ll get all the posts in JSON format.
E.g.
Here, You may confuse about how these data look like.
It’s a JSON format that shows like a big string.
To see the formatted output of the JSON data then install the browser extension.
I’m using the Chrome browser so, I’m installing the JSONVue chrome browser extension.
After installing and activating the extension, just refresh the page.
You’ll see the formatted JSON output as:
Pages Pages
/wp/v2/pages: {}, /wp/v2/pages/(?P<id>[\d]+): {}, /wp/v2/pages/(?P<parent>[\d]+)/revisions: {}, /wp/v2/pages/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+): {}, /wp/v2/pages/(?P<id>[\d]+)/autosaves: {}, /wp/v2/pages/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+): {},
Media Media
/wp/v2/media: {}, /wp/v2/media/(?P<id>[\d]+): {}, /wp/v2/media/(?P<id>[\d]+)/post-process: {}, /wp/v2/media/(?P<id>[\d]+)/edit: {},
Menu Items Menu Items
/wp/v2/menu-items: {}, /wp/v2/menu-items/(?P<id>[\d]+): {}, /wp/v2/menu-items/(?P<id>[\d]+)/autosaves: {}, /wp/v2/menu-items/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+): {},
Blocks Blocks
/wp/v2/blocks: {}, /wp/v2/blocks/(?P<id>[\d]+): {}, /wp/v2/blocks/(?P<parent>[\d]+)/revisions: {}, /wp/v2/blocks/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+): {}, /wp/v2/blocks/(?P<id>[\d]+)/autosaves: {}, /wp/v2/blocks/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+): {},
Templates Templates
/wp/v2/templates: {}, /wp/v2/templates/lookup: {}, /wp/v2/templates/(?P<id>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w-]+): {}, /wp/v2/templates/(?P<parent>[\d]+)/revisions: {}, /wp/v2/templates/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+): {}, /wp/v2/templates/(?P<id>[\d]+)/autosaves: {}, /wp/v2/templates/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+): {},
Template Parts Template Parts
/wp/v2/template-parts: {}, /wp/v2/template-parts/lookup: {}, /wp/v2/template-parts/(?P<id>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w-]+): {}, /wp/v2/template-parts/(?P<parent>[\d]+)/revisions: {}, /wp/v2/template-parts/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+): {}, /wp/v2/template-parts/(?P<id>[\d]+)/autosaves: {}, /wp/v2/template-parts/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+): {},
Navigation Navigation
/wp/v2/navigation: {}, /wp/v2/navigation/(?P<id>[\d]+): {}, /wp/v2/navigation/(?P<parent>[\d]+)/revisions: {}, /wp/v2/navigation/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+): {}, /wp/v2/navigation/(?P<id>[\d]+)/autosaves: {}, /wp/v2/navigation/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+): {},
Types Types
/wp/v2/types: {}, /wp/v2/types/(?P<type>[\w-]+): {},
Statuses Statuses
/wp/v2/statuses: {}, /wp/v2/statuses/(?P<status>[\w-]+): {},
Taxonomies Taxonomies
/wp/v2/taxonomies: {}, /wp/v2/taxonomies/(?P<taxonomy>[\w-]+): {},
Categories Categories
/wp/v2/categories: {}, /wp/v2/categories/(?P<id>[\d]+): {},
Tags Tags
/wp/v2/tags: {}, /wp/v2/tags/(?P<id>[\d]+): {},
Menus Menus
/wp/v2/menus: {}, /wp/v2/menus/(?P<id>[\d]+): {},
Users Users
/wp/v2/users: {}, /wp/v2/users/(?P<id>[\d]+): {}, /wp/v2/users/me: {}, /wp/v2/users/(?P<user_id>(?:[\d]+|me))/application-passwords: {}, /wp/v2/users/(?P<user_id>(?:[\d]+|me))/application-passwords/introspect: {}, /wp/v2/users/(?P<user_id>(?:[\d]+|me))/application-passwords/(?P<uuid>[\w\-]+): {},
Comments Comments
/wp/v2/comments: {}, /wp/v2/comments/(?P<id>[\d]+): {},
Search Search
/wp/v2/search: {},
Block Renderer Block Renderer
/wp/v2/block-renderer/(?P<name>[a-z0-9-]+/[a-z0-9-]+): {},
Block Types Block Types
/wp/v2/block-types: {}, /wp/v2/block-types/(?P<namespace>[a-zA-Z0-9_-]+): {}, /wp/v2/block-types/(?P<namespace>[a-zA-Z0-9_-]+)/(?P<name>[a-zA-Z0-9_-]+): {},
Global Styles Global Styles
/wp/v2/global-styles/themes/(?P<stylesheet>[\/\s%\w\.\(\)\[\]\@_\-]+)/variations: {}, /wp/v2/global-styles/themes/(?P<stylesheet>[^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?): {}, /wp/v2/global-styles/(?P<id>[\/\w-]+): {},
Settings Settings
/wp/v2/settings: {},
Themes Themes
/wp/v2/themes: {}, /wp/v2/themes/(?P<stylesheet>[^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?): {},
Plugins Plugins
/wp/v2/plugins: {}, /wp/v2/plugins/(?P<plugin>[^.\/]+(?:\/[^.\/]+)?): {},
Sidebars Sidebars
/wp/v2/sidebars: {}, /wp/v2/sidebars/(?P<id>[\w-]+): {},
Widget Types Widget Types
/wp/v2/widget-types: {}, /wp/v2/widget-types/(?P<id>[a-zA-Z0-9_-]+): {}, /wp/v2/widget-types/(?P<id>[a-zA-Z0-9_-]+)/encode: {}, /wp/v2/widget-types/(?P<id>[a-zA-Z0-9_-]+)/render: {},
Widgets Widgets
/wp/v2/widgets: {}, /wp/v2/widgets/(?P<id>[\w\-]+): {},
How to show the Rest API data? How to show the Rest API data?
There are different ways to access the Rest API data.
I’m showing you how to access it with the help of the JavaScript fetch() method.
fetch( 'https://maheshwaghmare.com/wp-json/wp/v2/pages/' ) .then( res => res.json() ) .then( allPages => { console.log( allPages ); })
The output you’ll see something as below:
See the code pen for more details:
https://codepen.io/maheshwaghmare/pen/dyjYEjz
List of All Default Endpoints List of All Default Endpoints
/wp/v2/posts: {}, /wp/v2/posts/(?P<id>[\d]+): {}, /wp/v2/posts/(?P<parent>[\d]+)/revisions: {}, /wp/v2/posts/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+): {}, /wp/v2/posts/(?P<id>[\d]+)/autosaves: {}, /wp/v2/posts/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+): {}, /wp/v2/pages: {}, /wp/v2/pages/(?P<id>[\d]+): {}, /wp/v2/pages/(?P<parent>[\d]+)/revisions: {}, /wp/v2/pages/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+): {}, /wp/v2/pages/(?P<id>[\d]+)/autosaves: {}, /wp/v2/pages/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+): {}, /wp/v2/media: {}, /wp/v2/media/(?P<id>[\d]+): {}, /wp/v2/media/(?P<id>[\d]+)/post-process: {}, /wp/v2/media/(?P<id>[\d]+)/edit: {}, /wp/v2/menu-items: {}, /wp/v2/menu-items/(?P<id>[\d]+): {}, /wp/v2/menu-items/(?P<id>[\d]+)/autosaves: {}, /wp/v2/menu-items/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+): {}, /wp/v2/blocks: {}, /wp/v2/blocks/(?P<id>[\d]+): {}, /wp/v2/blocks/(?P<parent>[\d]+)/revisions: {}, /wp/v2/blocks/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+): {}, /wp/v2/blocks/(?P<id>[\d]+)/autosaves: {}, /wp/v2/blocks/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+): {}, /wp/v2/templates: {}, /wp/v2/templates/lookup: {}, /wp/v2/templates/(?P<id>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w-]+): {}, /wp/v2/templates/(?P<parent>[\d]+)/revisions: {}, /wp/v2/templates/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+): {}, /wp/v2/templates/(?P<id>[\d]+)/autosaves: {}, /wp/v2/templates/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+): {}, /wp/v2/template-parts: {}, /wp/v2/template-parts/lookup: {}, /wp/v2/template-parts/(?P<id>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w-]+): {}, /wp/v2/template-parts/(?P<parent>[\d]+)/revisions: {}, /wp/v2/template-parts/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+): {}, /wp/v2/template-parts/(?P<id>[\d]+)/autosaves: {}, /wp/v2/template-parts/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+): {}, /wp/v2/navigation: {}, /wp/v2/navigation/(?P<id>[\d]+): {}, /wp/v2/navigation/(?P<parent>[\d]+)/revisions: {}, /wp/v2/navigation/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+): {}, /wp/v2/navigation/(?P<id>[\d]+)/autosaves: {}, /wp/v2/navigation/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+): {}, /wp/v2/rank_math_schema: {}, /wp/v2/rank_math_schema/(?P<id>[\d]+): {}, /wp/v2/rank_math_schema/(?P<id>[\d]+)/autosaves: {}, /wp/v2/rank_math_schema/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+): {}, /wp/v2/types: {}, /wp/v2/types/(?P<type>[\w-]+): {}, /wp/v2/statuses: {}, /wp/v2/statuses/(?P<status>[\w-]+): {}, /wp/v2/taxonomies: {}, /wp/v2/taxonomies/(?P<taxonomy>[\w-]+): {}, /wp/v2/categories: {}, /wp/v2/categories/(?P<id>[\d]+): {}, /wp/v2/tags: {}, /wp/v2/tags/(?P<id>[\d]+): {}, /wp/v2/menus: {}, /wp/v2/menus/(?P<id>[\d]+): {}, /wp/v2/users: {}, /wp/v2/users/(?P<id>[\d]+): {}, /wp/v2/users/me: {}, /wp/v2/users/(?P<user_id>(?:[\d]+|me))/application-passwords: {}, /wp/v2/users/(?P<user_id>(?:[\d]+|me))/application-passwords/introspect: {}, /wp/v2/users/(?P<user_id>(?:[\d]+|me))/application-passwords/(?P<uuid>[\w\-]+): {}, /wp/v2/comments: {}, /wp/v2/comments/(?P<id>[\d]+): {}, /wp/v2/search: {}, /wp/v2/block-renderer/(?P<name>[a-z0-9-]+/[a-z0-9-]+): {}, /wp/v2/block-types: {}, /wp/v2/block-types/(?P<namespace>[a-zA-Z0-9_-]+): {}, /wp/v2/block-types/(?P<namespace>[a-zA-Z0-9_-]+)/(?P<name>[a-zA-Z0-9_-]+): {}, /wp/v2/global-styles/themes/(?P<stylesheet>[\/\s%\w\.\(\)\[\]\@_\-]+)/variations: {}, /wp/v2/global-styles/themes/(?P<stylesheet>[^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?): {}, /wp/v2/global-styles/(?P<id>[\/\w-]+): {}, /wp/v2/settings: {}, /wp/v2/themes: {}, /wp/v2/themes/(?P<stylesheet>[^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?): {}, /wp/v2/plugins: {}, /wp/v2/plugins/(?P<plugin>[^.\/]+(?:\/[^.\/]+)?): {}, /wp/v2/sidebars: {}, /wp/v2/sidebars/(?P<id>[\w-]+): {}, /wp/v2/widget-types: {}, /wp/v2/widget-types/(?P<id>[a-zA-Z0-9_-]+): {}, /wp/v2/widget-types/(?P<id>[a-zA-Z0-9_-]+)/encode: {}, /wp/v2/widget-types/(?P<id>[a-zA-Z0-9_-]+)/render: {}, /wp/v2/widgets: {}, /wp/v2/widgets/(?P<id>[\w\-]+): {}, /wp/v2/block-directory/search: {}, /wp/v2/pattern-directory/patterns: {}, /wp/v2/block-patterns/patterns: {}, /wp/v2/block-patterns/categories: {}, /wp/v2/menu-locations: {}, /wp/v2/menu-locations/(?P<location>[\w-]+): {}, /wp-site-health/v1: {}, /wp-site-health/v1/tests/background-updates: {}, /wp-site-health/v1/tests/loopback-requests: {}, /wp-site-health/v1/tests/https-status: {}, /wp-site-health/v1/tests/dotorg-communication: {}, /wp-site-health/v1/tests/authorization-header: {}, /wp-site-health/v1/directory-sizes: {}, /wp-site-health/v1/tests/page-cache: {}, /wp-block-editor/v1: {}, /wp-block-editor/v1/url-details: {}, /wp-block-editor/v1/export: {}
Frequently Asked Questions for Rest API Frequently Asked Questions for Rest API
What is a REST API endpoint in WordPress? What is a REST API endpoint in WordPress?
A REST API endpoint is a URL on a WordPress website that provides access to specific data or functionality via the REST API.
The WordPress REST API includes several default endpoints that allow developers to retrieve, create, update, and delete various types of WordPress content.
What are the default endpoints provided by the WordPress REST API? What are the default endpoints provided by the WordPress REST API?
The WordPress REST API includes several default endpoints, including /wp/v2/posts, /wp/v2/pages, /wp/v2/media, /wp/v2/users, /wp/v2/comments, and /wp/v2/settings.
These endpoints allow developers to access and manipulate various types of content on a WordPress site.
How can I use the WordPress REST API to retrieve data from my site? How can I use the WordPress REST API to retrieve data from my site?
You can use a tool like Postman or a programming language like JavaScript to make HTTP requests to the WordPress REST API and retrieve data from your site.
For example, you could use the /wp/v2/posts endpoint to retrieve a list of all the posts on your site, or the /wp/v2/media endpoint to retrieve a list of all the media items on your site.
Can I modify the default endpoints provided by the WordPress REST API? Can I modify the default endpoints provided by the WordPress REST API?
Yes, you can modify the default endpoints or create custom endpoints using the WordPress REST API.
You can use plugins like the REST API Custom Endpoints plugin or custom code to add new functionality to your site’s REST API.
Are there any security concerns I should be aware of when using the WordPress REST API? Are there any security concerns I should be aware of when using the WordPress REST API?
Yes, like any web API, the WordPress REST API can be vulnerable to attacks like SQL injection or cross-site scripting (XSS).
It’s important to make sure your site is running the latest version of WordPress and any plugins you’re using and to follow security best practices like validating user input and sanitizing data before it’s used in API requests.