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

Powered by WordPress.com.

Up ↑

%d bloggers like this: