In between penning the sequel to my novel and code polishing my side projects, I decided it was time to do another concept breakdown on some typical programming terms. Today I will be going over API’s, AJAX, and JSON. Because as a wise person once said: When you learn something new and don’t use it for a while, you inevitably lose it (or so I’m told).
Let’s get started, folks.
API’s or Application Programming Interface as a term was coined by Ira W. Cotton in 1968. The most basic definition of an API is that it is a software intermediary that allows two applications to speak to each other. That’s it! So when you use a social media app, check the daily weather, or send an instant message across the web, you are in fact using an API. Pretty neat, huh? API’s are also commonly used by businesses as a way to integrate functionality across the board of applications in these three ways:
- Private: The API is only meant for internal company usage.
- Partner: Specific business partners have access to the API because it allows the companies to exercise quality control by determining which apps are allowed access to the API, which then provides them with an additional revenue stream.
- Public: The API is openly available for use by the public and the software can be used and written in their platforms.
But wait, there’s more!
There are thousands upon thousands of API’s out there, but today we will be discussing web API’s, specifically SOAP and REST. Let’s highlight and compare them.
SOAP or Simple Object Access Protocol was designed with official, standardized protocols set from the World Wide Web Consortium. It is function-driven, stateless by default(but can be made stateful), and their API calls cannot be cached. Security supports WS-Security with SSL support and has pre-made ACID compliance. It requires more bandwidth and computing power to use and the messages only come in XML format. SOAP is best used for high-security applications, financial services, payment gateways, enterprise applications, CRM software, and other services that require sensitive information. The main advantage it has over REST is the high security and standardization. However, it does have comparably poorer performance, more complexity/difficulty, and overall less flexibility.
REST or Representational State Transfer on the other hand, is designed in an architectural style with loose guidelines and recommendations. It was created as a response to SOAP and considered more friendly to use. It is data-driven, stateless, and their API calls can be cached. Security supports HTTPS and SSL. It requires less resources than SOAP and the message it sends can come in a variety of formats including: plain text, XML, HTML, JSON, YAML, and more. REST is best used for public API’s in web, mobile, and social networks. It has better performance, responsiveness, scalability, and flexibility compared to it’s SOAP counterpart. However a caveat is there is a lack of security, and is not suitable for distributed environments.
Now that we covered the gist of web API’s, on to the next!
The entire exchange can be summarized in seven steps:
1. An event occurs on a web page (page loads, button is clicked, etc.)
3. The XMLHttpRequest object sends a request to a web server
4. The server processes the request
5. The server sends a response back to the web page
Last but not least, we get to some syntax for storing and sending data.
XML itself isn’t terrible, and there still are uses for it depending on the platform. XML is great because it holds any data type and can be used to send a text document with a ton of markup, but it is larger and requires more data to process. JSON was created to be limited and sparse, which is great for business purposes. To put it in perspective, AJAX requests are designed to create a richer user experience without bogging them down with annoying page reloading or frustrating wait times. Responsiveness is the name of the game, especially in a society that constantly needs instant gratification.
This concludes the briefest of summaries on API’s, AJAX, and JSON. Hope it helps all you aspiring coders out there! Stay tuned next time for more!