Insights about WordPress 4.7 REST API Endpoints
- January 20, 2017
- Leave a comment
The WordPress REST API feature plugin has been merged in the latest version WP 4.7 “Vaughan”. The latest version provides endpoints for WordPress content types. By using endpoints you can access WordPress website externally in proper format and create new, innovative, apps by accessing your website content. It also includes complete and functional API for mobile apps and client side scripts.
By using WordPress REST API developers can create, read and update content remotely via response in JSON. Using this API also makes the process language independent. Meaning that by making an HTTP request and using JSON response you can handle content remotely in any language. AJAX calls improve performance by spending less time while accessing data by using REST API.
Endpoints are functions that you can use with API for read and write content data. By using endpoint functions with parameters will send response to client.
These endpoints have the following features:
- Posts: Every type of post data like posts, attachments and pages can be accessed for the purpose of reading and updating
- Comments: Comments including pingback and trackback can be accessed
- Terms: All the taxonomies and their terms data can be accessed for the purpose of reading and updating
- Users: All the user data can be accessed using REST API. Note; Some of Post Author’s data is publicly accessible
- Meta: Every type of meta data like posts, comments, terms and users meta is accessible
- Settings: By using REST API settings fields, like site title or tagline, can be accessed for the purpose of reading and updating
Content API endpoints are used for public and private access. With private access users can read and write including posts meta and settings. Public data such as Posts or Terms can be accessed without any authentication. The WordPress core team has already taken security measures to resolve the privacy issue.
Endpoints can be accessed by using route name. For example:
In the example given above we can define route, base path and end points:
- Route: “wp/v2/posts”
- Base path: “wp-json”
Above route has three endpoints:
By using WordPress REST API Posts one can Read, Create, Update and Delete operations with the following endpoints:
- GET “/wp-json/wp/v2/posts” used to retrieve posts
- GET “/wp-json/wp/v2/posts/125” used for specific single post with post ID
- POST “/wp-json/wp/v2/posts” used to create new post
- DELETE “/wp-json/wp/v2/posts/125” used to delete posts with post ID