Do you use AppMySite?
If yes, have you ever wondered how your mobile app is automatically populated by content from your website?
If you’re new, AppMySite is a mobile app builder that allows you to create an app for your WordPress website. The app you build on the platform syncs your website data and renders it in the app environment automatically.
This is made possible with the help of WordPress REST APIs
WordPress REST APIs allow developers to access the data on a WordPress website without needing to log in to the website’s admin panel. It is the easiest way to import WordPress data to a third-party application.
AppMySite uses WordPress REST APIs to access your website’s posts, pages, and other data. While using our free online app maker, you may have wondered why AppMySite supports some plugins and not others. Since we use official WordPress REST APIs, we can only support plugins that do the same.
For syncing your website plugins with AppMySite, understanding the role of REST APIs can help. This article explains how WordPress REST APIs exactly work.
APIs and REST: A brief overview
Let’s first understand the significance of APIs and REST before delving into their role in WordPress.
The following sections provide a brief overview of both.
What are APIs?
API is short for Application Programming Interface. It is basically an interface that allows two systems to communicate.
Let’s start with a simple example. You must have seen share icons on websites that allow you to share a post or article on social media. When you click on these icons, a pop-up opens up which allows you to post the content from your social media account.
This functionality works because the website and social media platform interact with each other through APIs. The social media website is able to access the content being shared via APIs.
APIs are best known for making application data accessible. Applications generally import data from third-party sources through APIs.
Another interesting example of an API is Google Maps. You must have noticed how several ride-sharing and food delivery apps use Google Maps. These apps use the Google Maps API to track and map locations.
Without APIs, these apps would have to create their own map system.
APIs are thus crucial for enabling seamless access to data between different platforms and applications.
What is Representational State Transfer (REST)?
APIs enable different web systems to communicate with each other. The examples in the previous section show how websites and apps can use APIs to create powerful functionalities.
However, what happens when two systems cannot understand each other? After all, not all APIs are built in the same way. Due to differences in the way two systems are built, they may not understand each other effectively.
This is where REST comes in. Representational State Transfer or REST provides standards that two interacting systems must follow in order to effectively communicate with each other. Systems that follow REST standards are able to effectively communicate with each other.
What makes a particular web system compliant with REST standards? The following points cover the attributes of a RESTful system:
- Stateless: RESTful systems must follow a stateless protocol. Stateless protocols basically imply that clients can send requests which can be understood by the server in isolation. Previous communication data is not required in stateless protocol to execute a request from the client. The server also remains in the same state when the API makes a request.
- Layered system: A layered system implies that information can be stored in intermediate servers. The server cannot thus always make out if a request is coming directly from a client.
- Caching: The responses of the servers should be cacheable to make the web systems perform faster.
- Interface uniformity: The URLs used to send requests to the server should have a uniform format.
- Client-server architecture: This simply implies that web systems must have a separate client and server infrastructure
REST APIs can be understood as standardized web systems that are designed to understand each other. WordPress REST APIs specifically refers to an interface using which external web systems can interact with WordPress websites.
WordPress REST APIs: Authentication and Commands
We now have a fair idea about WordPress REST APIs and their applications. If you wish to show data from a WordPress website in another application, you can use WordPress REST APIs.
The question now comes down to execution. How do you actually use WordPress APIs to access the resources of a website?
This brings us to authentication.
REST API Authentication
When you make an API request, you need to authenticate the request to ensure that the WordPress database authenticates your request.
This can now be done with the help of WordPress Application Passwords.
Application Passwords are unique codes you can generate in the admin panel of your website. These passwords can be used by third-party tools to authenticate REST API requests.
You can generate application passwords through the Users module in your WordPress admin panel. Additionally, you can choose to set with read-only access or read & write access for the application passwords you generate.
The scope of using Application Password for REST API authentication is immense. With Application Passwords, third-party tools get much more access to the resources of a website.
REST API commands
WordPress REST APIs enable you to access information from a WordPress website’s database externally. This access is executed with the help of REST API commands.
In the following sections, we discuss common REST API commands used by third-party platforms to access information from a WordPress database.
The GET command is the most popular command used by third-party applications. It is basically used to retrieve information from a WordPress website.
The syntax of the command looks something like this:
This command will display all the published posts from a WordPress website in a third-party application.
There are several other arguments you can use to display posts, pages, and other assets of your WordPress website with the GET command. You can refer to the WordPress REST API Handbook for more information on how to effectively use the GET command.
The POST command is used to post new content on a WordPress website. It looks something like this:
This command will create a new post on your WordPress website. This post will be set in drafts. To add content to this post or manage its status, you can use the POST command.
You can also create new pages using this command.
The PUT command is used to change an existing resource on a website. For instance, if you wish to change the publishing status of your post, you can use the PUT command.
With the PUT command, you can first access specific posts & pages and then update them. Here’s an example:
This command will give you access to a particular post. As you may have noticed, the end of the command is accompanied by a unique post ID. Enter the post ID you wish to edit in the command to access it.
After entering this command, you can add new content to the post or change its status. The following code shows how:
“status” = “published”
“content” = “Hello world!”
This code will mark your post published and add the content ‘Hello World!’ to it.
As the name suggests, the DELETE command enables you to delete a resource on your website. The syntax is given as follows:
This command will delete a post on a WordPress website with the unique ID 101. The post will be moved to trash. To delete the post permanently, use the FORCE argument along with the delete command. Doing so will permanently delete the post from the website.
REST APIs: Why does AppMySite support some plugins and not others?
If you use the AppMySite app builder to make your own app, you may have faced plugin compatibility issues.
There are over 50,000 WordPress plugins in the market. Each is coded in a different way, and it is impossible for AppMySite to support every plugin out there.
AppMySite is integrated with official WordPress REST APIs. Your app is populated with website content with the help of REST APIs making requests to your website’s database.
What does this mean for plugin support? Firstly, AppMySite is much more likely to work with a plugin that is integrated with official WordPress REST APIs. Plugins not integrated with WordPress REST APIs are likely to struggle with AppMySite.
Also read: Plugin not working with AppMySite? Here are the next steps
If there’s a plugin you want AppMySite to support, it is a good idea to check if the plugin is integrated with official WordPress APIs. Alternatively, you can also choose to render webviews in your app.
WordPress REST APIs enable third-party platforms to access content from WordPress sites seamlessly. Intuitive platforms like AppMySite rely on REST APIs to sync website data to the app.
This article covers the essentials of WordPress REST APIs and how developers can use them to access the resources of a WordPress website. A basic understanding of REST APIs can help AppMySite users better understand plugin integrations and app connectivity on the platform.