What are API’s?
Application Programming Interface abbreviated as API can be considered a medium of communication between two different Applications. APIs are not new to us, when we transfer data between two applications, APIs are what make this possible. For example, when you open an URL from a document editor using a browser, the medium of communication between the document editor and the browser is known as an API and this may be termed as System Level API.
Next, let’s have a look at some of the Web-Based APIs which is the type of API that we are dealing with in this article.
Facebook Graph API
Facebook provides APIs through which other apps can read and write to Facebook Social Graph, known as Facebook Graph API. Find more here.
Google provides API for its different services. The iFrame player API provided by google allows you to embed YouTube videos on your website. Google also provides Google Maps API to be used with our location-based applications. Find more here.
Twitter API can be used to read and write to Twitter using an external app.
They all do this by exposing some of the internal operations to the outside world with limited access. Find more here.
Why API’s are important?
You might have noticed, some of our favorite apps provide an option to sign up with Facebook or Google. For this, they are using the API provided by Facebook or Google. This makes our life much easier because we don’t need to remember different usernames and passwords for all our favorite apps. Think about a gamer who saves his game into his DropBox whenever he completes a level. Yes, it’s possible if the developers of the game make use of APIs provided by DropBox. Hence we can say that APIs are good time savers.
With the data provided by an API, you are free to develop applications in any of your convenient programming languages. Hence we can say APIs make applications language-independent.
Most of our location-based apps are based on Google Maps. This is because Google provides API for their map services. This allowed many intelligent developers to come up with useful apps that come in handy when we are traveling. LocoMapia is one such app, which uses Google Maps API, to share your location with your friends.
What is REST API?
If the API service is based on REST architecture, it is known as REST API. What is REST architecture? REpresentational State Transfer (REST) is an approach to communication in web services. REST never requires much amount of bandwidth when compared to other architectures hence is used widely for web service.
What is JSON?
What is WordPress JSON REST API?
In simple words, we can say, WordPress JSON REST API, is an easy-to-use REST API for retrieving or updating your WordPress website data in Simple JSON format. Hence it’s not necessary that you should know anything about PHP to put up a WordPress blog.
To start with download the WordPress REST API plugin from https://wordpress.org/plugins/rest-api/ . This plugin provides easy-to-use REST API which will be available via HTTP. With this, you can grab your site’s data in JSON format which includes user details, taxonomies, posts etc.
Currently Available Services (With Version 1.2.4)
- wp-json – Show all the routes and end points.
- wp-json/posts – Create, read, update, delete posts.
- wp-json/users – Create, read, update, delete users.
- wp-json/media – Create, read, update, delete media items.
- wp-json/taxonomies – Read taxonomies and terms.
- wp-json/pages – Create, read, update, delete pages.
Let’s go through an example which provides the list posts in your WordPress blog in JSON format.
<Your wordpress blog url>/ wp-json/wp/v2/posts
This will provide you a JSON result with the list of posts that you have in your WordPress blog. An example result is given below.
Another example which lists all your pages,
<Your wordpress blog url>/ wp-json/wp/v2/pages
If you want to retrieve a single post you can filter the post result with post id,
<Your WordPress blog url>/ wp-json/wp/v2/posts/<id>
This will give you the details of the post with the mentioned post id.
You can also update an existing post and create a new one using WordPress REST API. You can find the complete documentation at http://wp-api.org.
- An exclusive mobile App for your blog.
- Custom-made Dashboard.
- Integration of content with other platforms and vice-versa.