WP- REST-API with cURL

API endpoint

[chen@luna ~]$ curl -l http://wp-api.pw/wp-json/

Posts

Get

The Posts endpoint returns a Post Collection containing a subset of the site’s posts.

[chen@luna ~]$ curl -l http://wp-api.pw/wp-json/posts

Post

Create a Post Requires authentication

[chen@luna ~]$ cat data.json
{
    "title": "This is a post",
    "content_raw": "This is some content"
}
[chen@luna ~]$ curl --user test:password -X POST http://wp-api.pw/wp-json/posts --data @data.json

Delete

Delete a Post Requires authentication

[chen@luna ~]$ curl --user test:password -X DELETE http://wp-api.pw/wp-json/posts/229
{"message":"Deleted post"}

Media

Post

To create the raw data for an attachment. This is a binary object (blob), such as image data or a video.

[chen@luna ~]$ curl --user test:password -H 'Content-Type:image/jpeg' -H 'Content-Disposition: attachment; filename="test1551.jpg"' -X POST http://wp-api.pw/wp-json/media --data-binary @/home/chen/IMG_1551.jpg

Users

Get

This endpoint offers a permalink to get the current user, without needing to know the user’s ID.

get user self

[chen@luna ~]$ curl --user test:password http://wp-api.pw/wp-json/users/me

get user list

[chen@luna ~]$ curl --user test:password http://wp-api.pw/wp-json/users