Themergency fooplugins.com

WordPress REST API

| 1 Comment

This is day 20 of my WordPress Developer Advent Calendar.

I love how all new major additions to WordPress core are being developed as plugins first, so that they can be tested and put through their paces. One of these plugins is WP-API, which gives your WordPress site a REST API. If you are unsure what REST is, then I suggest you read up on the topic first:

  • A Beginner’s Guide to HTTP and REST
  • What exactly is RESTful programming?

Make WordPress RESTful

To give this new feature a spin, this is what you need to do:

  1. Download the WP-API plugin and activate it on a local WP install.
  2. Make sure your permalinks are set to “post name”.
  3. Install the best API testing tool available : PostMan (this is a chrome extension).

Make Your First RESTful Request

Now that it is installed and running, open up Postman and do a GET request to:

http://local-wp-install/wp-json.php

Where http://local-wp-install is the location of your local WordPress environment. In my case it was http://wp/wp-json.php and you can see the result I got in PostMan:

WP-API First Request In Postman

The result you get back is a JSON document which includes all the RESTful URL’s or “routes” that you can now access in your very own API. Very cool. Now let’s get back all your posts. I did a GET request to http://wp/wp-json.php/posts, and the response was:

WP-API Posts

To get back a listing of all post types in your WordPress install, do a GET request to http://wp/wp-json.php/posts/types.

Now this is only the tip of the iceberg, and you can do a whole lot more with the API. For more detailed documentation, check out:

  • The Getting Started guide.
  • Working with Posts - how to retrieve, save, update and delete posts via the API.
  • Extending the API - really interesting for plugin authors.
1 comments
  Livefyre
  • Get Livefyre
  • FAQ
divinzer
divinzer

how can I get this API from remote domain in javascript?

this API cant allow remote access in javasciprt