Installing WP API

The current stable version of the WordPress API is on the WordPress.org plugin directory, and can be installed on your site via your WordPress admin. Beta and Development versions are on Github.

Once the plugin is installed and activated you can check for the API by loading `yoursite.com/wp-json` in your browser. You should see a block of JSON text.

It may be fun at this point to check on some other routes such as wp-json/posts. And if you visit wp-json/users you’ll get an authorization error because the API handles authentication via the same cookie that the WordPress admin uses.

Note: This lesson assumes you are using pretty permalinks on your site. Without pretty permalinks, an API route would look like for example `yoursite.com/?json_route=/posts`

The full set of routes and endpoints are listed for your benefit on wp-api.org

Pretty JSON

If you want to test out the routes and view well formatted JSON responses, try the Postman Extension for Chrome. Or, for example, use a command line helper to get pretty JSON

curl http://yoursite.com/wp-json/posts | python -m json.tool

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: