REST API & CRUD Basics

Read any WordPress REST API: four verbs, routes, status codes and the /wp-json/ index.

4 lessons16 interview questions

Every app speaks four verbs. WordPress does too. The REST API is already answering at /wp-json/ on every site you have ever built. In this module you learn to read it: which route does what, why a write returns 401, and why DELETE does not really delete.

CourseWordPress REST API Course ยท Module 1 of 9 ยท Stage 1 "Read the API"
LearnRoutes and endpoints, the four verbs of CRUD on wp/v2, query parameters, pagination headers and real core error codes
How4 short lessons on wp/v2/posts, requests you run with curl against your local site, interview questions after every lesson

Four verbs, one resource

flowchart LR
  C["POST /wp/v2/posts<br/>Create ยท 201"] --> R["GET /wp/v2/posts/123<br/>Read ยท 200"]
  R --> U["PUT /wp/v2/posts/123<br/>Update ยท 200"]
  U --> D["DELETE /wp/v2/posts/123<br/>Delete ยท trash"]
  classDef get fill:#ebf3fb,stroke:#61affe,color:#1e293b
  classDef post fill:#e8f6f0,stroke:#49cc90,color:#1e293b
  classDef put fill:#fff5ea,stroke:#fca130,color:#1e293b
  classDef del fill:#feebeb,stroke:#f93e3e,color:#1e293b
  class C post
  class R get
  class U put
  class D del

CRUD is the grammar, endpoints are sentences. Once you read one resource, you read them all.

Before โ†’ after

BeforeAfter Module 1
"The API is somewhere in WordPress"/wp-json/ index: every namespace and route on the site
A 401 looks like a bug401 rest_cannot_create: write requests need auth
"I deleted it" โ€” it is in the trashDELETE trashes; force=true deletes for good
Loading all posts at onceper_page, page, X-WP-Total, X-WP-TotalPages

You'll be able to answer

  • What is the difference between a route and an endpoint in the WordPress REST API?
  • Which HTTP methods does WordPress accept for an update?
  • What does DELETE /wp/v2/posts/{id} do without force=true?

Lessons in this module 4 lessons