What API’s are?

rest

Application Programing Interface, abbreviated as API can be considered as medium of communication between two different Applications. API’s are not new to us, when we transfer data between two applications, API’s are what make this possible. For example when you open an URL from a document editor using browser, the medium of communication between document editor and 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 API’s which is the type of API that we are dealing with in this article.

Facebook Graph API

Facebook provides API’s through which other apps can read and write to Facebook Social Graph, known as Facebook Graph API. Find more here.

Google API

Google provide API’s for their 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

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 operation to the outside world with a limited access. Find more here.

Why API’s are important?

You might have noticed, some of our favourite 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 favourite apps.  Think about a gamer who saves his game into his DropBox whenever he completes a level. Yes its possible if the developers of the game make use of API’s provided by DropBox. Hence we can say that API’s are good time savers.

With the data provided by an API you are free to develop applications in any of your convenient programming language. Hence we can say API’s make applications language independent.
Most of our location based apps are based on Google Map. This is because Google provides API of their map services. This allowed many intelligent developers to come up with useful apps that come handy when we are travelling. LocoMapia is one of such apps, which use 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 of 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?

JavaScript Notation abbreviated as JSON is a format which is used to interchange data between two applications. JASON is lightweight and easy to understand when compared to XML. And it’s easy and fast to be generated and parsed by machine.

What is WordPress JSON REST API? (Form this point you should be aware what WordPress is)

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 WordPress REST API plugin from https://wordpress.org/plugins/rest-api/ . This plugin provides easy to use REST API which will br available via HTTP. With this you can grab your sites data in JSON format which includes user details, taxonomies, post 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.

wp-post

Another example which lists all your pages,

<Your wordpress blog url>/ wp-json/wp/v2/pages

Result:

wp-page

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 WorsPress REST API.  You can find the complete documentation at http://wp-api.org.

Use Cases

  • An exclusive mobile App for your blog.
  • Custom made Dashboard.
  • Integration of content with other platforms and vice-versa.

Posted by Nebu John Thaliyath

Leave a reply