blog posts

A Comprehensive Introduction to API

A Comprehensive Introduction to API

If you are looking for a simple and fast way to use different programs or services, you have probably heard the familiar term API. API is an acronym, but a powerful golden key for programmers that simplifies the integration of different applications. In this article, we intend to introduce you to this powerful communication bridge. After reading this content, you will know what API stands for and what protocols it has. You will also become familiar with its most popular types and applications.

What is an API?

API stands for Application Programming Interface. It acts like a communication bridge between two pieces of software, allowing programmers to use the capabilities of a system or program through specified functions and commands. For example, with one type of API, they can connect to a web service’s data or a cloud platform’s services. In fact, instead of coding a service from scratch yourself, you can connect to a service or server and receive its information by using an API. API is the master key to unlocking the iron doors of programming and discovering the secret path to communicate with various services.

What is an API

A Closer Look at the Concept of API

Now that we know what API stands for, let’s take a more interesting look at the concept of API. By 2018, more than 110,000 APIs had been introduced. The estimate for 2023 brings this figure to 500,000 APIs. This statistic shows the significant growth in the popularity of APIs among companies and organizations, a technology that has rapidly improved software development and inter-service communication. An API acts like a translator between two people speaking different languages. Suppose one person speaks English (the request sender) and the other speaks French (the request receiver). The API is their only means of communication as the translator between them. After knowing the “What is API?” answer, you must become familiar with how to use it. To use an API, you need information such as an API Key to connect to the desired service. After connecting, you can use the available functions and receive a response from the receiver.

A Clear Example of API Functionality

If you still haven’t understood the answer to “What is API?”, consider the following example: Imagine you intend to travel to a foreign country. To do this, you contact a travel agency to purchase tickets, reserve a hotel, and provide information and travel conditions for the desired country. Your communication channel to the destination country is this travel agency, which acts on your behalf to arrange your hotel and tickets. To go on this foreign trip, you need a travel agency. Similarly, to use web-based services, you need a web API to connect you to the desired program. An API is like a travel agency that, as your representative, facilitates your communication path with the destination service.

How API Works: How Does API Work?

In response, we must say that its operation depends on the type of API. Some APIs are contractual and based on agreement. For example, by placing a software’s API on your website, you send a request to the software. Then, upon the software’s approval of your request, a communication bridge will be established between your site and the software. With two simple examples, we will explain how an API works:

Example: When you purchase from an online store, you will see various bank payment gateways for online payment. This means the online store in question has enabled its connection to the bank gateway by placing the APIs of these banks on its site. When you click on one of the bank gateways for online payment, the API sends a request to the web server. Then, the web server connects to the server of the respective bank, and after receiving a response from the server, you will be redirected to the bank’s payment page.

Example Two: Suppose you have an online store that lacks adequate accounting capabilities. To record sales invoices and registered orders on the site, you need to manually enter each invoice into your accounting software to avoid accounting problems. Instead, you can place the accounting software’s API on your site without knowing how to work with the accounting software. This way, a communication bridge will be established between the site and the accounting software; consequently, invoices on the site will also be directly registered in the accounting system.

5 Examples of the Most Important API Applications

API has various applications. In this section, we want to examine the most common applications of API.

1. Google Maps API You have probably glanced at your phone’s Google Maps at least once to distinguish the right path from the wrong one. For services like Uber or any site that requests access to your location to determine your exact address, use Google Maps. In other words, they have placed the Google Maps API on their site.

2. Using Social Platforms On some websites, for consultation and purchase support, there is an icon for Telegram, WhatsApp, or chat, which, when clicked, redirects you to the support account page on the respective social network. If we want to examine a popular and practical example of an API, the ability to use Facebook, Twitter, Instagram, Telegram, or other social networks on sites can be cited. This feature enables websites to choose one of the popular social networks, making accessing and communicating with users easier.

3. Benefiting from the Internet of Things (IoT). What is the relationship between the Internet of Things and API? Smart devices offer their advanced functionalities through APIs. For example, imagine years from now, smart refrigerators will be introduced to the market, connected to cooking recipe programs, and will send cooking instructions to your mobile phone. In other words, the refrigerator will be connected to the cooking recipe program and the SMS service via API. Another clear example is CCTV cameras. Through the camera’s API connected to an application on your phone, you can easily check the environment with the CCTV camera from wherever you are.

4. Booking Travel Tickets and Hotels Have you noticed that when you want to book a travel ticket for your desired date, all travel websites display the same number of empty seats? Ticket booking sites respond to your request through APIs by collecting information from recent flights. This means that through the flight information database API, you will have access to the latest ticket status via a web browser or the travel companies’ applications.

5. Navigation Applications Do you know how applications like Google Maps or the popular Waze show us the route better than any guide? They even indicate speed cameras and traffic police. This capability is provided by connecting the API to various services such as traffic alerts, traffic police, and GPS.

Types of API by Access Level

There are four different types of API in terms of access level:

  1. Private
  2. Public
  3. Partner
  4. Composite

Next, we will examine each type of API:

1. Private API or Internal API: Developers and programmers use this API to improve an organization’s services. Private APIs are not placed in the hands of third parties like users. Instead, API access is only authorized for different teams, services, and applications within an organization. The company can use various authentication or encryption methods to maintain security and access levels. To better understand what a private API is, consider a large company like Amazon or Uber. The company’s finance department needs information related to sales and customer payments to prepare the company’s financial reports. The human resources department needs information such as salaries, job descriptions, attendance hours, and employee leave. The sales department also wants information such as product inventory, orders, and the product purchasing process. For communication between the different departments of such large organizations, the company defines a private API within the organization so that each department can access the information needed by other departments. Thus, Amazon or Uber employees have access to each department with this API, and on the other hand, the company also thoroughly monitors employee access to the API.

2. Public API or Open API Public APIs, as the name suggests, are available for public use. Prominent examples of this type are Twitter, Facebook, Telegram, WhatsApp, and Google Maps APIs. With public APIs, you can communicate with other services or platforms to offer your services and products, either for free or by paying a subscription fee. For example, you can display Instagram posts by connecting the Instagram API to your site. Whens a blog post or product is published on your site, its corresponding post is automatically displayed on Instagram.

3. Partner API This API can only be used through an agreement between the providing and receiving companies. Partner APIs are often used in business affairs to establish communication between two companies’ software. This means the company providing it allows its partners to connect via a Partner API. Suppose you have an online store. To advertise your products, you want to use the services of pay-per-click advertising companies. Their API needs to be placed on your site to display your products through these companies. This way, you can advertise your products using their site. This example is a type of partner API.

4. Composite API Composite APIs are used for more complex services. They are like today’s smartphones compared to old button-based Nokia phones. In a composite API, several APIs process a request simultaneously and coordinate to display the final output to the user. That is, it uses the capabilities of different services to display a new function or ability. Imagine instead of checking the weather with one program, navigation with another, and accessing news with yet another, you could access all three programs through one API. In other words, simplify your work through an API incorporating each of the three APIs.

Introducing APIs Based on Usage Type

APIs can be categorized into different types based on usage. Below, we introduce 6 of the most common types of APIs based on access type.

1. Operating System (OS) API: An Example of a Proprietary API This type of API enables operating system services or middleware to connect to various applications. For example, Microsoft’s .NET APIs, Windows API, or Linux APIs are proprietary for each operating system. This type of API allows programmers to access and control operating system files and capabilities using the functions and resources of each operating system.

2. Web API: An Example of a Public API What is a Web API? It is designed to display resources such as HTML pages and is accessible to everyone using a simple transfer protocol. Every URL activates a web API. By using web APIs, programmers can easily connect to web services and add more application capabilities. APIs of social networks like Pinterest, electronic payment services, and Google Maps are examples of web service APIs. For instance, with the Pinterest API, you can transfer your account information to your website. With an electronic payment service API, you can enable internet payment on your site. Also, with the Google Maps API, you can add a location map to your site.

3. Remote API: An Example of a Public API. With remote APIs, you can access resources outside your system. Two programs connect through a communication network. These APIs are written based on web standards. Examples include the Java Database Connectivity API and Java Remote Method Invocation API, two examples of remote application programming interfaces or Remote APIs.

4. Program API; A Type of Proprietary API Program APIs are based on RPC (Remote Procedure Call) technology. Through it, a part of a program, service, or operating system becomes accessible to an application software. These APIs are in the form of programming libraries or frameworks that provide functions and variables for other programs. In fact, programmers can add desired functionality to their programs without needing to write detailed code by using program APIs. For example, an SDK (Software Development Kit) is a program API that provides programmers with various libraries, tools, and code. This means that you no longer need to create independent HTTP requests by using the Twitter SDK instead of the Twitter web API. You can easily get your work done using the commands and libraries available in the Twitter SDK. Microsoft’s WS series falls into this category of APIs. Also, graphics APIs like OpenGL and DirectX are types of program APIs that allow programmers to draw 3D images in applications. The Android SDK is another example of a program API type that simplifies software development for Android developers.

5. Server AP:; A Communication Bridge Between Programmer and Serve. Among the types of APIs, the Server API can be named. This API acts like a communication bridge between programmers and the server, allowing programmers to use resources and services available on the server. Server APIs will enable you to use resources available on the server through requests and responses established under standards like HTTP. For example, suppose you have a web service that displays a list of users. You can send a request to receive the list of users to the server via the Server API and receive it from the server.

6. Database API: A Connection Bridge Between Programmer and Database Data. Database APIs are a type of API that allows applications to connect to databases. This way, programmers can update the database data with their programs. For example, the Drupal database API will enable developers to write unified queries for different databases. Database APIs can be used for MySQL, Oracle, and MongoDB databases.

Types of API Protocols

An API protocol is a type of standardized agreement between different services. Learn about the most common API protocols for creating seamless communication between different systems.

1. Service Object Access Protocol (SOAP) The SOAP protocol is a protocol for transferring information between different systems that works based on HTTP or HTTPS. The SOAP protocol follows strict rules for sending requests and responses for web applications. Each message in this protocol consists of a header and a body. The content of the body section is in XML text format. Using this protocol, you can often connect to web-based software. APIs for payment gateways and customer relationship management are examples of the SOAP protocol. Consider a mailbox. You drop a letter into this box to be delivered to your destination by the postman. Your letter is packaged as a paper parcel and sent via post. If we consider the paper packaging to be the XML text messages, sending them via post is the SOAP protocol.

Advantages of SOAP Protocol:

  • Acts according to functions.
  • Has more complex rules for developers.
  • Creates greater security for web applications.
  • Works with XML format. This format supports images, diagrams, numbers, and text.

2. Remote Procedure Call (RPC) Protocol.RPC in API protocols is often used in remote calls. This means, like a telephone that connects you with someone on the other end of the line, in the RPC protocol, a program requests a service from a server located on another system in the network. To understand better, imagine you are in a remote city and intend to communicate with your friend in another town by telephone. You call your friend’s phone, your connection is established, and after finishing the conversation, you hang up. In this example, you made the first request and waited for your friend’s response. Then they also received your call and responded. A similar thing happens in the RPC protocol. A client sends a request to another server (your friend’s phone), and the server (your friend) responds.

Advantages of RPC Web API:

  • They are a good option for adding commands and procedures.
  • Supports both JSON and XML formats.
  • CRUD commands create, read, update, and delete data.
  • In RPC, the GET command is used only to retrieve information, and the POST command is used to modify information.

The following three protocols are known as members of the RPC protocol family:

1. XML-RPC Protocol The XML-RPC protocol transfers data in XML format. It is older than SOAP but simpler and relatively lighter because it uses minimal bandwidth.

2. JSON-RPC Protocol JSON-RPC is also a type of remote request, but instead of XML format, it uses JSON (JavaScript Object Notation) to send responses.

3. gRPC Protocol This universal open-source framework is newer than the SOAP protocol and uses http/2 technology for connection and data transmission. Google introduced gRPC in 2015. This protocol uses protobuf as its description language instead of XML or JSON. With this protocol, you can call methods and commands directly from the application server on another computer. gRPC simplifies the creation and distribution of services and applications.

3. Representational State Transfer (REST) Protocol Web APIs are often RESTful. Unlike SOAP, which only supports XML, RESTful offers various formats like plain text, XML, YAML, HTML, and JSON. APIs use HTTP requests like GET, PUT, HEAD, POST, PATCH, CONNECT, TRACE, OPTIONS, and DELETE to perform operations. To better understand this protocol, imagine you have a web service that provides resources like a library, writings, user lists, and other items. By sending a GET request from you, the server creates a new resource and a unique identifier and sends you the response to your request. In the REST protocol, resources are identified by URLs, and information for each resource is sent in the format of HTTP messages and structures like JSON or XML. The JSON text format is one of the lightweight formats for data exchange, and its instruction is based on the ECMA-262 3rd Edition standard. The format of JSON files is such that it can be used for any programming language. The REST protocol has gained remarkable popularity thanks to this JSON format because it is easily usable for different technologies.

Advantages of REST Web API:

  • Optimized for web applications.
  • Works with a uniform interface.
  • Works with JASON text and numerical formats.
  • Operates based on the given data, not functions.
  • Consumes low bandwidth for application creation. It has comprehensive and straightforward instructions for developers when building applications.

4. GraphQL Protocol; The Query Language of Servers. GraphQL is a server-based query language that allows developers to send precise requests to receive data from the server. Unlike the REST protocol, which sends a separate request for each resource, in the GraphQL protocol, you can send only a single request for the server to respond with the information you need. In other words, you can build a structure of your desired requests in one query and specify particular fields for the response to your request. Ultimately, the GraphQL server, by examining the request structure and the data architecture you provided, collects the desired data and delivers it to you as the final response. Large companies like Shopify, Yelp, GitHub, Coursera, and The New York Times use the GraphQL protocol to build APIs.

How to Use an API

To receive and use an API, you have the following steps ahead:

1. Obtain Necessary Information and Documentation. The Necessary information refers to the entry address, Endpoint, and the type of requests you intend to send.

2. Review the Required Information and Content. In the second step, you must review the content you intend to receive. For example, if you want to receive a list of users, you need to know what fields are required to receive this information.

3. Create and Send Your Desired Requests. After learning the type of requests and required fields, you can create your desired requests at this stage. Depending on the type of API, you may send commands like GET, POST, PUT, and DELETE. After making the request, you must send it using a library or programming tool.

4. Receive and Process the Response. After sending the request, you will receive a response from the server in the final stage. This response will be in JSON file format, and the required information will be delivered based on your request.

Monetizing API (What is API Economy?)

The API Economy concept refers to the exchange of APIs between a service provider and a customer. When a company uses the data services of other services and, in return, sells APIs, the concept of API Economy is formed.

Three Simple Examples to Understand the API Economy Concept: Many companies initially offer APIs for free to attract more audiences and fans for their brand. After a while, they earn income by selling them to those who need APIs.

  1. Uber is a clear example of the API Economy. Uber provides a robust and powerful API that enables access to transportation services. Other companies, like Google Maps, can use this API and integrate their services with Uber’s.
  2. Following the model of large-scale e-commerce facilitators, some regional online marketplace aggregators provide their proprietary APIs to numerous online stores. This enables these stores to gain visibility and increase their sales by being featured on the aggregator’s popular platform. Consequently, the aggregators can generate income from these API services and potentially charge a recurring fee to the participating stores.

  3. Consider a book distribution company. To better manage and satisfy users, this company can introduce a service to its customers where users can check book availability in a cloud environment. Developing and implementing such a program can be costly and requires programming expertise. In this situation, the book distribution company can define an API for accessing the book inventory. With this API, customers will have information related to book inventory in one collection.

Securing API: How do you provide security for an API?

First, try to set up your API on a server separate from the database it is connected to. Also, using SSL and TLS will make it impossible for hackers to access your information. Using this certificate will also increase trust between the user and the server. In addition, you can limit API access only to authorized individuals. To do this, you can use tokens like OAuth or JWT to verify users’ identities. Filtering and validating user input data also prevents attacks like XSS.

What are the Advantages of API?

In addition to simplifying access to resources, management, and integration of applications, API are secure and controllable. These two features, security and controllability, have turned it into a valuable technology. Also, having a Layer of Abstraction has made work easier for programmers. A layer of Abstraction helps programmers provide a better experience of their program with the API without getting involved in technical complexities and coding hassles. The concept of Layer of Abstraction can be likened to the driving skill. For driving skills, you do not need to know details such as how the engine, braking system, and gearbox work, and by using simple tools like the steering wheel, handles, and pedals, you can control the car. A layer of Abstraction also makes programming work easier for programmers to design simpler and more practical programs without needing to know the details. The most popular advantages of API can be said to be:

  • Ability to connect and interact with external services
  • Increased security and control
  • Saving time and money
  • Adding features and program development
  • Compatibility, coordination, and integration of programs

APIs also create an additional layer to protect user privacy. You have probably experienced that when you visit a site or application for the first time, the website or application asks for permission to access your location and address via API. This way, you can reject or approve this request.

Advantages-of-API

Conclusion

Like a smooth road, API establishes the communication path for programmers with various programs and services. In this article, we thoroughly answered this question. We examined types of APIs and their related protocols. We cited critical applications of API and finally looked at the advantages of API. We thank you for being with us until the end of this article.