What is an API?
What is API?
API is a term consisting of the initials of the structure referred to as 'Application Programming Interface'. Although it may seem quite new, the foundations of API date back to the 1940s. It was first mentioned in an article in 1968 as a part of modular software shaped entirely on needs. So, what is Application Programming Interface? Theoretically, it is an architectural solution with unique data and principles, does not reflect unnecessary code complexity by accelerating processes, and enables applications to communicate with each other.
To answer the question of what API does with a real-life example: When you go to a restaurant, you usually see a menu on the table and convey the dishes and drinks you want from this menu to the waiter. The waiter passes the order information to the kitchen. After the order is prepared in the kitchen, the waiter takes these products from the kitchen and brings them to your table. When we look at this process, the waiter is a messenger that tells the order information to the kitchen, that is, what to do to the system, so we can call it an API.
APIs are divided into types according to their intended use:
- Open API and Public API: Open API can be used by applications authorized with a key, while Public API is open to all applications.
- Internal API and Private API: Internal API is used in internal systems. Private APIs are private APIs that are not open to every user.
- Partner API: There is more than one user. We can call it a combination of Open API and Private API.
- Composite API: A combination of one or more data/service API interfaces.
When applications want to access information that is not usually available on their own, they can get the information by contacting the applications that have this information. This is done through an API. Applications may need to go to many data sources using different methods to access this information. This increases Code Complexity and the code you need to manage. API saves you from many inconveniences like this.
API has gained many features over the years, making itself valuable and useful. APIs account for some of the revenues of many companies such as Google, Amazon, Booking, and eBay.
An important feature provided by APIs is security. APIs transmit the information you want by evaluating it according to the keywords they receive from you. At this point, since you are the party accessing the API, they do not have any information about your device/system or application. They do not have any information other than what you give to the API and do not request it from you.
How Does API Work?
We can answer the question of how to use an API by looking at its working principle step by step:
- When an application on the device wants to be used, this application connects to the internet and transmits some information to the server. This information can be specified by the API as optional or mandatory fields.
- The server receives and interprets this information. During the interpretation, different tasks can be performed with the help of this information. With the information received, the API can perform some queries in different data sources or take actions (such as adding, updating, and deleting records). These situations are completely related to what the API does. After the interpretation process is completed, the server where the API is located returns information to the device.
- The information returned from the server is read and interpreted by the application on the device. The information returned by the API and the information presented to the user may differ structurally. If the API can perform some operations on the information it requests, the application on the device must also be able to perform these operations. It can apply the methods related to what it will do while interpreting the information returned from the API, and the data prepared with the interpretation of the information returned from the API by the application on the device is presented to the user.
APIs have come to this day by solving many problems. The modern API is a concept created by the problems experienced. Technologies are shaped according to needs. The usage rates of technologies that cannot meet the needs decrease over time. At this point, the API has continuously improved itself and made itself preferred. The modern API has attracted all the attention with its highly understandable and easy-to-communicate structure for developers. The fact that it is documentable has given developers a lot of momentum in terms of understandability and speed. In addition, its compatibility with HTTP and Rest Standards paved the way for using many technologies.
Why-How to Use an API?
With the development of technology in today's world, companies can no longer fully reach their customers with web applications. At this point, the answer to the question 'Why Use API? People have started to do their shopping, order food, and even request a cleaner from their phones or tablets. This has made people's lives easier and changed the way they develop applications. Modern APIs are of great importance for applications to be developed more efficiently and faster.
When we want to prepare an API that can be accessed over the HTTP protocol (we can call these APIs Web APIs), all the services offered by this API will become documentable. The usage methods of each service may be different from each other. It is important to remember that security is a very important parameter. Web APIs support all methods of the HTTP protocol. Get, Post, Put, and Delete operations are the most important ones and CRUD (Create Read Read Update Delete) operations are transmitted to the Web API with the help of these methods. Today, almost all applications use APIs in this way.
API examples can be evaluated and analyzed in many areas according to the usage area. For example; Let's examine the use of API on Koton.com.tr:
Koton.com.tr has thousands of products. When the customer likes a product and adds it to the cart while browsing through the products, the user's member information and product information are transmitted to an API, which interprets the information and transmits it back to Koton.com.tr to be reflected to the user with a different model. When the user opens the cart screen, they see the product there and press the buy button. When the user completes the payment process, the product information, the information returned from the bank, and the customer information are transmitted to a different API. The information is interpreted and stock control is done to create an order. When all parameters are appropriate, the stock is reduced by the sales amount and information is transferred to the relevant unit to prepare the order to be sent to the customer's address. Afterward, Koton.com.tr is notified that the order was successful. Koton.com.tr interprets the information received from the API and reflects it to the customer as "Your order has been completed successfully". If you have noticed, to complete the order, the API that Koton.com.tr has accessed reaches a different API to ask for stock information. Data can be exchanged through many different APIs like this.
Web APIs can be hosted in an application or on IIS/Apache Server. With the .Net Core brought to the software world by Microsoft, Web Applications can now run on Linux without the need for Windows Server. Web APIs can be prepared in any language. Many alternative technologies such as Go, Python, and .Net have advanced API features. The prepared API can be published over an IP (e.g. 220.127.116.11/api) or a DNS Name (e.g. https://www.koton.com.tr/api). As we mentioned in the API types, it is possible to develop APIs that are only application-based or open to all users. For this, server or Web API user authorization definitions must be made. Users can be prevented or restricted from accessing via IP or DNS Name.