3

I have been coding for quite a while on Python now but never fully understood, given an example, what an API is.

Things I've heard:

  • It something that defines the interaction between multiple software intermediaries
  • A software intermediary that allows two applications to "talk" to each other

But what I'm not getting is this: what is "talking" here? Are we only referring to sending HTTPS requests? Is it a library or collection of libraries? What qualifies as being an API?

I once had to gather some information off of a server (I'm not sure of the technical terms here) from a website made by Django. I had to do this through an API. How I actually did it, with Python, was by using a library called requests. Is this library an API?

Another example is with Google's OCR Tesseract, wherein its documentation they mention that "Developers can use libtesseract C or C++ API to build their own application." What is API referring to here?

If someone can help me put this all into context, it would make my week.

marsnebulasoup
  • 2,530
  • 2
  • 16
  • 37
  • 1
    It all varies on how much detail you want. Basically you can say that every module that offers public methods to call has an API (which is, the methods to call). And as always: https://en.wikipedia.org/wiki/API – Niloct Dec 16 '20 at 17:19
  • 1
    This answer does a pretty good job of distinguishing between a module vs. an API: https://teamtreehouse.com/community/the-difference-between-module-vs-api – marsnebulasoup Dec 16 '20 at 17:20
  • So the "calls" aren't necessarily https calls. They refer to method calls too? Besides when they mention allowing two applications to "talk", could you give an example of what library achieves this "talking"? – Kamal Raydan Dec 16 '20 at 17:29
  • @marsnebulasoup They recycle the typical definition given online. At this rate if an API is something that provides you with the building blocks to build a program then isn't basically any and every library a sort of API? – Kamal Raydan Dec 16 '20 at 17:32
  • 1
    Does this answer your question? [What exactly is the meaning of an API?](https://stackoverflow.com/questions/7440379/what-exactly-is-the-meaning-of-an-api) – Maritn Ge Dec 16 '20 at 17:44
  • @KamalRaydan - An API, in a sense, would be a set of instructions or rules, allowing you to interact with an application, programatically. You use the instructions to communicate properly with the application. However, I believe more often, the word *API* is used to refer not only to the instructions for communicating/interaction with an application, but the application you are interacting with, itself. For example, if you say that you fetch data from the, say, Youtube API, you would be referring to the application itself, not just the instructions to communicate with the application – marsnebulasoup Dec 16 '20 at 17:47
  • 1
    An API is basically something you use to get data, without accessing the database. e.g. the openweathermap API gives you weather data when you send requests via GET requests. the twitter API can get you tweets and so on. (correct me if i'm wrong this is my understanding on an api) in your example the API is just this, a place that provides data for you – Maritn Ge Dec 16 '20 at 17:50
  • 1
    @MaritnGe It absolutely does! There is a link within the post you linked to me that just did it for me! – Kamal Raydan Dec 16 '20 at 18:16
  • 3
    An API is a *contract* for exchanging information. If you make a call to a typical REST API you have a *protocol* (HTTP) over which you send data in a *data format* (e.g. JSON) and get a response back. But you can swap out the pieces: with a library you have a protocol (function call) through which you send data (funargs) and get back a response. The API doesn't (usually) specify those pieces (i.e. *how*), what it defines is the *what*: what you need to give the thing you're communicating with and what you get back. Don't confuse the protocol/data format with what an API is. – Jared Smith Dec 16 '20 at 18:20
  • Beautiful way of putting it @JaredSmith! – Kamal Raydan Dec 16 '20 at 18:28
  • @KamalRaydan glad to hear i could help! – Maritn Ge Dec 16 '20 at 20:56

0 Answers0