WordPress Rest API- An Introduction - SkillBakery Studios


Post Top Ad

Post Top Ad

Monday, December 7, 2020

WordPress Rest API- An Introduction

 What is the WordPress REST API?

The WordPress REST API is an interface which gives us access to WordPress functionality from outside the WordPress installation itself. You access it using JavaScript, which means it can be used to create interactive websites and apps. REST stands for Representational State Transfer and API stands for Application Programming Interface. Let’s take a look at what each of those means.

 What is the API?

An API in simple definition means protocol which involves interaction of client and server which enables smooth building of client and server programs. To put it more simply, an API is a set of code that allows one system to interact (or “interface”) with another. These systems may or may not need to be completely separate. WordPress already has multiple APIs, for things like plugins, settings, and shortcodes. These can be used by plugin and theme developers to interact with WordPress core and make things happen (like creating shortcodes and adding settings screens to the WordPress admin).The only difference with the REST API is that it allows systems outside your WordPress installation itself to interact with WordPress, which is where the REST part comes in.

What is Representational State Transfer (REST)

Representational State Transfer, or REST, provides standards that web systems can use to interface with each other. Without REST, two systems wouldn’t be able to understand each other and so send data back and forth.

For an application to be RESTful, it must conform to five principles:

Uniform interface. The URLs used to access resources in the system have to be uniform, consistent, and accessible via a common approach such as GET (more of which shortly).

Client-server. Client applications and server applications must be separate, so they can be developed independently of each other. If the server-side technology (i.e. WordPress) changes, the server-side application (an app, for example) must still be able to access it via the same simple method.

Stateless. The server doesn’t change state when a new request is made using the API. It doesn’t store the requests that have been made.

Cacheable. All resources must be cacheable, to improve speed and conformance to web standards. Caching can be implemented on the server or client-side.

Layered system. A RESTful system lets you use multiple layers to access it, storing data in intermediate servers if it needs to. The server can’t tell if the final client is directly connected to it.

All of these constraints relate to web pages and applications and govern the way an application can interface with the API.

What Does This Mean for WordPress?

Putting REST and API together means that the WordPress REST API is a set of code designed to make it possible for other systems to interface with WordPress and that it’s built in a way that ensures these systems will understand each other. It means that a third-party website or a mobile app, for example, can access your WordPress database, fetch data from it, and add data to it via some interface which is not wordpress admin dashboard. There are lot of applications for the same which we will discuss in next posts

No comments:

Post a Comment

Post Top Ad