Why do we need an API ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why do we need an API ?

Ok I know what an API is . An API is a system that allows programs to communicate with each other . What I don't get is why we need a system to manage this communication . Isn't communication as simple as sending a query and getting a response . Why do we need a system to manage something that simple ?

1st Nov 2021, 7:44 AM
Richard
Richard - avatar
7 Answers
+ 6
Sometimes it is. But sometimes the API a) wraps knowledge eg. which data table is to query b) bundles common code patterns c) helps if other protocols than sql are needed (tcp/ip) d) makes coding faster, safer and/or easier in general
1st Nov 2021, 7:56 AM
Oma Falk
Oma Falk - avatar
+ 6
An API has typically two sides: we can call them Provider and Consumer. The provider offers a service to respond to the consumer, according to the "contract" of the API that is it's specification. The provider usually publishes the description of the API (at least if it's public, then users must be aware how they can converse with this API). APIs have various forms and protocols... A very common one is a web API which can also have a variety of forms: SOAP, REST, gRPC. In this case the provider is a web server and the consumer is accessing it via HTTP. Web APIs are very popular because they are language-agnostic, they can be a bridge between very different systems, languages and locations. Another type of API is any programming language's own standard building blocks and libraries, which the developers can use to create programs. In this case the "surface" or "contract" of the API is the function / method signature that you are accessing.
1st Nov 2021, 5:39 PM
Tibor Santa
Tibor Santa - avatar
+ 4
Generally speaking, computer systems are dumb. They cannot communicate with each other unless we teach them how to. Even between humans, communication can be a challenge - we agree in some implicit terms, for example when you ask a question on this forum, you are writing in English, you formulate a headline and a description of your problem, you add tags. There is also some hidden context of your question that we, smart humans might guess, based on our experience with the subject. Heck, we are so smart that sometimes we can even give meaningful answers to very badly formulated questions with missing context. However when it comes to computers, they can only really deal with structured data in a prearranged and well-defined format, which is known to both sides beforehand. That's why APIs are needed, they establish the ground rules for the communication: what questions can be asked, what kind of answer can be expected, what happens if information is not available or communication is unsuccessful.
1st Nov 2021, 1:37 PM
Tibor Santa
Tibor Santa - avatar
+ 1
Used to integrate with other plaftorms i.e either programming database cloud crm erp etc
1st Nov 2021, 11:39 AM
sree harsha
sree harsha - avatar
+ 1
API is important thing
2nd Nov 2021, 10:11 AM
Abülfazl Molavi
Abülfazl Molavi - avatar
+ 1
An API can have multiple, broader, meanings and usages depending on the context. To explain as broadly as possible, we could create a program that let any other program feed code in directly but, this is obviously a bad idea. We want to make sure the request another program are making are OK and we don't want to allow them to do just anything. So, we expose an API filled with approved requests that we control. Another broad point here is that the two programs may not have a common language but we might still want them to talk to each other so we can expose a common enough API like a scripting language to do the talking. In your example , send a query and get a response, how should the other program structure and send the query? What kinds of queries can it send? How will a program process the query? That is all an API "system" is.
2nd Nov 2021, 6:02 PM
Kail Galestorm
Kail Galestorm - avatar
0
APIs stops the direct interfare or access of data from sever database, by any application. It provides a level of security to the database.
3rd Nov 2021, 7:11 AM
Akshat Sharma