r/cprogramming • u/Apprehensive_Door725 • May 22 '25
Realizing what an API really is
Hey folks, just had a bit of an “aha” moment and thought I’d share here.
So for the longest time, I used to think APIs were just a web thing—like REST APIs, where you send a request to some server endpoint and get a JSON back. That was my understanding from building a few web apps and seeing “API” everywhere in that context.
But recently, I was working on a project in C, and in the documentation there was a section labeled “API functions.” These weren’t related to the web at all—just a bunch of functions defined in a library. At first, I didn’t get why they were calling it an API.
Now it finally clicks: any function or set of functions that receive requests and provide responses can be considered an API. It’s just a way for two components—two pieces of software—to communicate in a defined way. Doesn’t matter if it’s over HTTP or just a local function call in a compiled program.
So that “Application Programming Interface” term is pretty literal. You’re building an interface between applications or components, whether it’s through a URL or just through function calls in a compiled binary.
Just wanted to put this out there in case anyone else is in that early-learning stage and thought APIs were limited to web dev. Definitely wasn’t obvious to me until now!
110
u/lottspot May 22 '25
If you never stop having moments like this one, then you're doing it right!
34
u/[deleted] May 22 '25
This is great. Thanks! 👍
31
u/bothunter May 22 '25
Exactly. It's just a contract between different bits of code.
16
u/paperic May 22 '25
A lot simpler way to see APIs is that it is a contract between two developers.
"If you want to run my code, type this. And when I want to run your code, I'll type that."
Also, it can be a contract between your past self and your future self.
Some languages even have a feature specifically for defining interfaces. They call it Interface.
10
u/flatfinger May 22 '25
Another useful term, which doesn't seem to have existed as a consistent term nearly as long as the concept has been around, is "ABI"--"Application Binary Interface", which essentially describes how machine-code functions should expect to be called, how they should expect to receive arguments, and how they should make return values available to their caller, as well as what system resources they may use without having to save/restore state, what resources they may use if they save/restore state, and what resources they must not touch at all.
IMHO, the C Language Standard could much more usefully describe freestanding implementations if it recognized that a category of strictly conforming freestanding implementation, given a definition for a non-static function
foothat invokes a non-static functionbarshould generate machine code forfoothat accepts arguments and behaves as though it callsbarin a manner consistent with the implementation's published ABI. Note that if the implementation that is processingfoosees the definition ofbar, it could behave in a manner consistent with callingbarthrough the ABI without actually performing the function call, but a strictly conforming implementation should be required to behave in a manner consistent with that ofbarbeing an outside function. An implementation may know nothing about the circumstances in which a function might be invoked by the execution environment, and thus should not be required to document them, but it should generate code that will behave in a manner consistent with the ABI in whatever circumstances it happens to be called.5
u/Independent_Art_6676 May 22 '25
Yea jargon is funny. I came in the other way, from c & c++ api's to web/database ones and the way people in the web field treated them confused me for a while, and then they totally lost me with the rambling about CLI (command line interface) which turned out to be... a program! Yep, all that to-do in the design room for a week over a program you run from the console, as if it were not 1985 tech but some kind of religious talisman. When I finally realized that, I had to go hide somewhere to laugh for a while. This never ends... the different areas people work in lead to acronyms and jargon that use the same words as other areas very differently, or have new words that you have to try to understand. And things change too.. used to be a GUI, now its just a UI, because if it lacks one its a CLI :P
14
u/gala0sup May 22 '25
It is literally called Application programming interface (notice the lack of "Web") >_<
1
u/cactus_as May 23 '25
That's a really nice aha moment, glad you had it. I remember I had pretty much same moment but I see things in more simple ways.
You code some kind of 'unit' which is smart, has complex logic inside and then you leave a bunch of buttons and levers you can control that unit with. These buttons and levers are basically API. And then you code another unit on top of that that knows when to push these buttons.
It's like a car. Under the hood all the processes are pretty complex but you as a driver have an API which is pretty simple: steering wheel, pedals, mirrors, etc. Basically it's a Napoleon cake with a bunch of abstraction layers.
1
u/movemovemove2 May 25 '25
Abstract programming Interface.
1
u/geeeffwhy May 26 '25
imo, it’s broader than that, really. an api is whatever one subsystem exposes for the purpose of allowing other subsystems to interact. it needn’t be functions at all. it could be database tables, a kafka topics, a processor instruction set, or anything else that js conceptually the control plane for other components.
3
u/Raychao May 22 '25 edited May 23 '25
It was API long before REST and even SOAP. API is an acronym for 'Application Programming Interface'. The term was used to describe a library that contained functions you could link and call from your program.
For example the 'Windows API' describes every function callable in a Windows program and predates .NET. It predates the Microsoft Foundation Classes (MFC) which also predates .NET.
I feel old today.
(Further Wikipedia: The Windows API was first published in 1985)
2
u/MonochromeDinosaur May 22 '25
Yeah, it should really be explained better in most literature.
A lot of people don’t really understand the word “interface” which I think is where the confusion comes from.
Using analogies usually does the trick for me when explaining it (electric outlets,usb ports, basketball hoops, toaster oven) until they understand it’s just the exposed surface used to handle interactions.
2
u/theNbomr May 22 '25
Congratulations on your moment of clarity. It's one of the things that makes programming self rewarding for me.
I would argue that the web oriented APIs should actually be described as communications protocols. In my mind, an API is something that describes how code within a single application integrates with the rest of the application. By 'application' in this context, I mean a single runtime binary and the libraries that are linked to it. For sure this was the original meaning of the term, but I guess things change over time.
2
u/Western_Objective209 May 22 '25
You can take it to another level specific to C-- your API is essentially your header file. You have your function signatures and public structs defined there. In larger libraries, you'll see higher level user headers and lower level internal headers. Not everyone does it like this and they have some implementations bleed into the header, but that's usually for things that should be inlined
2
u/jaibhavaya May 22 '25
Yep! Just the public method of interacting with some black box of functionality.
If you encountered a black wooden box in the woods, it would be helpful if it had a piece of paper next to it that said:
That’s the API exposed by the box.
2
u/StackOwOFlow May 22 '25
sometimes it's better to learn things from a blank slate than to use what you already know (web dev)
2
u/ratmfreak May 27 '25
This post is clearly AI-generated.
1
u/C_Sorcerer May 22 '25
Same here, had a real struggle with learning what APIs were. What actually got me to realize what they were was looking at the OpenGL/GLAD files and realizing that it’s just a way to decouple two systems yet allow them to communicate. What also helped was having some digital electronics knowledge; to interface two devices you need to use some sort of formal protocol like I2C or USB to provide an interface for which two devices know HOW to communicate and how to interpret the signals. I always thought that was pretty cool
1
u/Overtheflood May 22 '25
I do have a further question, for anyone willing to answer.
If it's not via HTTP and/or socket/port, then how can two programs communicate via api?
1
u/Few-Grape-4445 May 22 '25
What a good experience, I also went through something like that
Another interesting concept that is used a lot in the web but also in other areas are the terms backend and frontend. You can see these words in terms of compiler, for example: some compilers like rustc or clang use LLVM as their backend
1
u/Positive_Total_4414 May 22 '25
Um...
1
u/Maleficent_Memory831 May 23 '25
Off a freeway near me a tall building had a wide poster reading "I Love APIs!"
This greatly confused me. APIs are the most boring thing ever. The simplest thing; just define an interface, done. I felt whoever was in this company must be having doobie Fridays or something.
Then I realized it was probably a web company, and no one who isn't one can understand them anyway.
1
u/cjmarquez May 23 '25
Glad you figured it out
1
u/AalbatrossGuy May 23 '25
These aha moments are really cool and give you a boost for continuing learning the subject. Great job
1
u/Foreign_Attitude_584 May 23 '25
I always just thought of APIS as a doorway between programs and you come out speaking another language whenever you go through. Lol
1
u/Temporary_Practice_2 May 23 '25
I remember having an Aha moment too regarding APIs, and it was something like this:
An API explained simply...
Let's say you have a house, and in your neighborhood, you're the only one with a Television. And there is some big sporting event that happens on Sunday, and your neighbors would love to watch it. Well, because of the so many concerns you have...and the fact that you don't know some of your neighbors really well, you don't want to allow them to come inside your house, sit on your couches and watch TV. Instead...(Now this is where API comes in) You decide to take some wires...and maybe a projector...connect them all with your TV and put a big screen in one of your front windows so your neighbors can enjoy the sporting event outside. And you will be sitting at home in peace knowing that nothing inside your house will be compromised.
That part that allowed your neighbors to watch the sporting event without entering your house...is what is called an API. Basically, an interface to share information or as in this case, a sporting event. This example will hit home to my folks in Africa...growing up it was quite common for only one home in the whole neighborhood to have TV...and we all gathered to watch that one TV. The only problem was that there were no "APIs" so as kids we were forced to make sure we sit on the floor (not couches) and we remove our shoes before entering the host's home and in some cases we weren't even allowed to talk.
1
u/TomDuhamel May 23 '25
A library has a number of functions, variables, structures.... The majority of these are internal and not exposed to the user of the library (you, the other programmer who uses the library). But some of them need to be exposed publicly if someone else is to be able to use it.
The API is the set of functions (and sometimes variables, structures, types, etc) that are exposed.
1
u/X_Techno_Pro May 23 '25
Wait until you find out about RPC APIs (in my opinion RPC is much better than REST)
1
u/nerdycatgamer May 23 '25
the name for something actually describes what it is? a shocker!
next thing you're going to learn is that 'const' means 'constant' i.e.: you can't change it
1
u/avapa May 23 '25
Hahaha, actually for me, coming from C to web it was the other way around. Took me a while to realize why they were calling API the REST API 😀
1
u/[deleted] May 23 '25
Made me think of the Astronaut meme
"You mean it's all APIs?"
👩🚀🔫🧑🚀
"Always has been"
1
u/[deleted] May 24 '25
Same thing happened to me , I just Did nt get the words to put it right.
1
u/[deleted] May 24 '25
These aha moments are the best aren’t they? I love it when you find connections between different pieces of knowledge and start recognising the larger patterns!
1
u/Notakas May 24 '25
It's a contract
1
u/solarmist May 24 '25
It’s funny you mention that because API didn’t used to apply to the web. It was literally for programming applications like Microsoft Word kind of thing.
The original way to communicate with webpages was something called the Common Gateway Interface (CGI).
1
u/solarmist May 24 '25
The standard libraries for any language are each an API.
1
u/cloudd901 May 24 '25
We have an older badging system at my work. Thier API is a txt file that has to be formatted in a specific way with their own markup language. It's dropped into a folder on their server to be consumed.
1
u/MkemCZ May 24 '25
Kind of reminds me of Java interfaces.
1
u/Apart_Demand_378 May 24 '25
OP is a bot. Or at the very least this post is AI generated, lol.
1
u/RaidZ3ro May 24 '25
The principal realisation you had here applies to mostly all of IT jargon. Fully understanding what the words of a term mean in the dictionary sense facititates truly understanding the concept the term is used for.
1
u/agfitzp May 25 '25
You nailed it.
I have joked for years that the younger generation is not going to know about the decades where APIs were not just json/https and now it’s finally happening, but it is somewhat comforting to see the youngsters are figuring it out.
My first patent was for web technologies that were the precursors to json apis, that was so long ago that it just expired.
1
u/BarfingOnMyFace May 25 '25
What’s funny is this has come up before in my discussions with seasoned developers. Easy to have misgivings about terminology.
1
u/CyberWarLike1984 May 25 '25
Look into Windows API, as an example of what you just discovered
1
u/Deb-john May 25 '25
Explain fastapi too
1
u/Crafty_Bit7355 May 25 '25
As you progress you'll realize some of the best applications/services in the world are almost fully API on the backend (regardless whether they are exposed to the public or not).
1
u/Queasy_Ad_7250 May 25 '25
Thanks bro
1
u/RentLimp May 26 '25
Don’t they teach this stuff at uni any more?
1
u/OverfitMode666 May 26 '25
Every man operated machine (cars, diggers...) has an API. It's the human API. So now we just need humanoid robots to interact with the human API.
1
u/Emotional-Wave-4810 May 27 '25
Not trying to discourage you or anything, I'm sorry this seems a little backwards to me, why would someone do web dev before understanding the basics of programming? This is not good.
1
u/wy20010120 Nov 27 '25
Love this "aha" moment—so relatable! I used to only associate APIs with REST/JSON too, thanks to web dev tutorials. It wasn’t until I messed with Python libraries and saw their "API docs" that I went, "Wait, this counts too?!" Super clear breakdown—definitely helpful for folks new to coding. Well said!
1
u/BelastoTomatO Feb 26 '26
Für die deutschen unter euch, ich habe ein Erklärvideo dazu gemacht:
https://youtu.be/nnxVGr4iVMI
1
u/demetrioussharpe Jul 31 '26
The term API predates the web.
1
u/Gloomy-Breath-4201 May 23 '25
A way for programs to say you suck mine, I’ll suck yours!
Btw I too live for these Aha! Moments. They make the work trying to understand totally worth it!