What Is a REST API?
A REST API is a standard way for one system to communicate with another over the web.
Instead of a person clicking buttons on a website, a program can send a request directly to another system and receive a response back.
Simple way to think about it
You can imagine it like this:
- Your Python script = the customer
- WordPress = the kitchen
- REST API = the waiter
Your script tells the API what it wants to do, and the API passes that request to WordPress. WordPress then sends back the result.
What does it do?
A REST API allows programs to work with data such as:
- posts
- pages
- users
- categories
For example, with WordPress, a script can:
- create a blog post
- read existing posts
- update a post
- delete a post
How it works
REST APIs usually use:
- URLs to represent data or resources
- HTTP methods to describe the action
- JSON to send and receive data
A WordPress API endpoint for posts looks like this:
https://yourwebsite.com/wp-json/wp/v2/posts
This URL represents the posts resource.
Common HTTP methods
The main methods are:
- GET → read data
- POST → create data
- PUT / PATCH → update data
- DELETE → delete data
Examples:
GET /posts→ get blog postsPOST /posts→ create a new postPATCH /posts/123→ update post 123DELETE /posts/123→ delete post 123
Why this matters
A REST API makes automation possible.
Instead of manually logging into WordPress and creating a post, a Python script can do it for you.
That means you can automate tasks such as:
- daily blog posting
- saving posts as drafts
- updating content automatically
- posting data from another source
Simple example
Imagine your script sends this data to WordPress:
{
"title": "Daily blog",
"content": "Today I want to write about..."
}
It is basically saying:
Please create a new post with this title and content.
WordPress may respond with something like:
{
"id": 101,
"title": "Daily blog",
"status": "draft"
}
This means the post was created successfully.
Python example
Here is a simple example of Python creating a draft post in WordPress through its REST API:
import requests
from requests.auth import HTTPBasicAuthurl = "https://yourwebsite.com/wp-json/wp/v2/posts"data = {
"title": "My first API post",
"content": "Created from Python",
"status": "draft"
}response = requests.post(
url,
auth=HTTPBasicAuth("your_username", "your_app_password"),
json=data
)print(response.json())
In short
A REST API is a web-based interface that allows one program to send instructions and data to another in a standard format.
In the case of WordPress:
- Python sends a request
- WordPress receives it
- WordPress returns a response
That is the basic idea behind a REST API.