WordPress REST API & CRUD

Every app speaks four verbs. WordPress too: /wp-json/wp/v2/

CRUD:

  • Create → POST /wp/v2/posts
  • Read → GET /wp/v2/posts/{id}
  • Update → PUT /wp/v2/posts/{id}
  • Delete → DELETE /wp/v2/posts/{id}

Read is open for public data: GET returns 200 with X-WP-Total and X-WP-TotalPages. Write? Prove who you are: POST without auth returns 401 restcannotcreate. DELETE moves a post to the trash first; ?force=true deletes it for good.

Your own API uses the same grammar: registerrestroute( ‘4wp/v1’, … ) with a permission_callback.

CRUD is the grammar. Endpoints are sentences.

Go deeper