Maker.io main logo

How important are APIs in IoT

2016-04-14 | By Maker.io Staff

Raspberry Pi Photon Arduino BeagleBone

More often than not it is becoming very common for developers to come across some reference to APIs, or application programing interfaces. All the big giant tech firms such as Google, Microsoft, Facebook and twitter all have their own APIs for developers to integrate their projects into one another with ease.

If you work with APIs, then you should already know how important they are in technology today. But for the rest, you may wonder, "What are APIs and why do we need them so much?"

In the simplest terms, APIs are a set of requirements that determine exactly how applications can talk to each other. APIs have been around for many years; whenever you use your everyday computer or smartphone, APIs make it possible to transfer information between programs such as copying and pasting from one application to another, which is done using a system-level API in the OS.

On the web, APIs allow big everyday services such as Google maps, Facebook or twitter to integrate with other applications features. Take a moment and think about the way TripAdvisor works, by displaying local hotels, restaurants and attractions on a google map using its own web data, or mobile games that allow users to invite their friends through Facebook or Google+.

APIs accomplish all of this by revealing some of a program's internal code to the outside world in a very restricted limited ability to avoid any security mishaps. That makes it possible for applications to share data and take actions on the others behalf without requiring developers to share all their code. Code-sharing on a large scale would be very unethical for most programmers to consider and also be inefficient.

This is also a true statement for many open-source applications. Nobody has the time to check all the code for someone else's applications just to use one function of the application. Every programmer has a different method of writing and annotating code; and there could be millions of lines of code to look through!

APIs simplify this issue by limiting outside program access to a specific set of features, which are often requests for data for a particular service. The best way to think of this process is doors and windows, where every door opens to a different house and every house is different. APIs clearly define exactly how you can interact with the rest of the world, ultimately with the purpose of saving a massive amount of time, resources and the possibility of legal entanglements.

How APIs work

APIs in recent technology, are especially important because they determine how developers can create new applications that can integrate with web services such as Facebook, Twitter or DropBox. A developer for a mobile gaming application may want to use DropBox to store saved game progress; otherwise the shear amount of work involved in adding this feature could be costly. In one sense, APIs are great time savers in that they also offer end user convenience for logging into websites using Facebook's API.

Looking at the wider picture, APIs make it possible for developers to create a mashup of different web services to enhance the overall end user experience. When you do a search for restaurants or hotels in a particular city using Trip Advisor, for instance, it will plot its location on Google maps instead of creating its own mapping feature, via the Google Maps API. Trip Advisor application passes the information it wants plotted (restaurant’s, star rating etc.) on the map and combines it with an internal Google Maps function that then returns a Map object to display within the application. You probably see APIs like this more frequently, even if you decide to share this article with your friends, you will do this using APIs by that particular service.

APIs are not always good

Relying on some APIs can be risky business, especially when the majority of your application is built around using an API. Just because the API is available for you to use now, that doesn't mean at some point in the future the developer may decide to switch that feature off or make the whole API service redundant. Potentially the cost of up keeping an API could out weight the benefits of releasing it in the wild. A good example of this is the massive amount of Google APIs which get shut down every year such as Google Health and Google Reader. This shutdown of services can leave your application in limbo if it solely depends on its' APIs.

Some companies that provide APIs will also limit the amount of user requests an application can make to its service. This throttling can cause issues in your application if the level of traffic is generally quite high. This throttling is actually quite common amongst APIs and it prevents the impact of a DDoS attack to their system.

Different Types of APIs in IoT services

APIs based around the IoT are mostly web service APIs and they can come in different forms such as SOAP, REST or XML/JSON. A web service is a piece of software, or a system, that provides access to its services via an address on the web. This address is known as a URL. This web service offers its information in a format that other applications can understand or parse through. Examples of popular web service APIs are Flickr API, Google maps API and Google maps web services API. When an application or client wants to communicate with a web service, the application sends back an HTTP request to the client in response. In the response request, much of the information is passed in the URL itself as paths or parameters.

In addition to the standard URL, HTTP requests and responses will include information in the header and the body of the message. Request and response headers include different various types of metadata, such as the browser being used or the content type. The body includes additional data in formats such as XML and JSON.

SOAP – Simple Object Access Protocol

SOAP is a protocol that defines the method of communication between the client and the server. The transfer of data is done in a XML format. A SOAP web service publishes a definition of its interface in a machine-readable document using web services definition language.

XML and JSON

XML and JSON are much older methods than SOAP. Instead of using a specific format for data transfer, both methods use a simpler approach to calls and tend to use much less bandwidth, which sometimes can be preferred.

REST – Representation State Transfer

When working with IoT hardware development boards such as Particle Photon, Arduino Yun, Raspberry Pi, Intel Edison/Galileo, BeagleBone Black/Green plus many more; chances are you will be using a Restful API to communicate your electronic hardware with the rest of the world using a IoT software platform. REST APIs are a set of architectural principles rather than a protocol. Some of the features required for a REST service include the simplicity of interfaces, identification of resources within the request made and also the ability to manipulate the resources via that particular interface.

From the client side of an application using REST, REST services offer and easy-to-parse URL structure, made up of mostly nouns that would identify the logic and hierarchical categories of the data available.

API Management

API management is an umbrella in which a collections of solutions are grouped together; such as gateways, security and access management. API management also includes developer registration and API key control. An API service will need to grant developers who enable the connecting of devices to APIs the authority and associated key to do this whilst retaining the right to remove access when necessary.

A good example of a web service that provides good API management is IFTTT service (if this then that). IFTTT gives users creative control over 300 devices and application services using something called recipes. Recipes are simple connections between products and apps. Just recently, BMW car manufacturing group has created their own channel which allows users to get the most out of their car. It allows drivers to trigger events when you park, speed or arrive at a destination, and furthermore you can receive custom notifications straight to your in-car dashboard.

Summary

Overall, without the use of APIs in the IoT applications we see today, they simply would not exist; the growth and development in the technological area would be halted somewhat and we would be simply relying more on SDKs. Whilst SDKs are useful tools, they do require a higher skill set for most applicable developers, this can lead to substantial lead times in deliverable projects and also higher costs in hiring more skilled developers for completion.

TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum