Using REST API

Using the WordPress REST-API you can create a plugin to provide entirely new admin experiences for WordPress, build a brand new interactive front-end experience, or bring your WordPress content into completely separate applications.

There are 5 main key concepts of REST API that you should know before starting using it.

  • Routes & Endpoints – A route is a URI that can be mapped to different HTTP methods. The mapping of an individual HTTP method to a route is known as an endpoint.
  • Requests – A request made in WordPress is an instance of WP_REST_Request class, which is used to store and retrieve information for the current request.
  • Responses – Responses are the data you get back from the API. The WP_REST_Response class provides a way to interact with the response data returned by endpoints. 
  • Schema – API Schema is a data structure of input and output data of each endpoint.
  • Controller Classes – It manages the registration of routes & endpoints, handling requests, utilizing schema, and generating API responses.

You can find more details on these concepts here. Also refer to the Glossary handbook page.

Learn more about how to interact with API resources and query for specific data in the Using the REST API section. Also, refer to the Endpoint Reference handbook page to know all the default endpoints provided by WordPress.

Explore these videos for insights and tutorials on REST API. This section comprises 4 modules with a combined duration of approximately 30 minutes.

Video ContentTime
Introduction to REST API11:20
Parameters 10:33
More on REST API & Discovery02:29
Authentication & Endpoints on Custom Post Types06:16

Ideas to Explore:

  • What are custom routes in the WP REST API, and how do I create them?
  • How can I authenticate WP REST API requests?
  • Create a custom route that fetches all the posts associated withrt-celebs CPT along with pagination.
  • Is it possible to restrict REST API requests from only one host/URL? If yes, how?
  • What’s CORS? How can you enable CORS in WordPress REST API?