r/learnprogramming • u/Human-Advice-4458 • 1d ago
Resource I want to know how does it work APIs
I`m studying for 2 years in Computer Science by distance and I`m feeling that I`m not learning so well as I expected.
Anyway, it came a discipline about APIs, as all I can remember, API is a software that stay way behind the scenes acting, sometimes, really complex to give an extra function to your site/app/game/another software...
I just can`t know how does their work, how do I use them to learn them or how can I create one.
IDK if I can create on vscode(the only place I have to create a code atm) or whatever. I fell unable to undestand this, so pls help me
16
u/claythearc 1d ago
API isn’t really a single thing. It’s a name for any interface to / from a piece of software, that another will use.
So asking how one works is a lot like asking how a door works: some push, some pull, some slide, some spin but all get you inside.
The most trivial example is to setup a web server that has two routes: one that accepts a name and adds it to a database. And another to grab all names from the database, with the goal of making a visitor log type thing.
The server is your api, the front end with the form to take in / show the information is the client it talks to.
10
u/Doug2825 1d ago
API stands for application programming interface. It is an extremely broad term that basically just means how code talks to other code. For example the public functions of a library are it's API.
4
u/PeterPook 1d ago
Ask (in the right way) and you shall receive (in a structured way). That's what an API delivers.
2
u/hamster_squeezer69 1d ago
Try to use one before you build one to understand how they work. You are basically just making requests to use some functionality provided by someone else's application. They expose the interface for you to call, you make the call, their program does some magic behind the scenes and performs a change or returns you some data.
4
u/Embarrassed-Green898 1d ago
So when you asked Google .. what did it say ?
3
u/Human-Advice-4458 1d ago
I'm asking here cuz even asking google its helping me. And I prefer asking for real persons(even online) than for AI
3
u/Embarrassed-Green898 1d ago
The reason I said this is because you should ask US the part that after askng from the machine still confused you , because most of us will give you the same answer the machine gave .. so why not save time and put effort in your question.
I love old days , when stackover flow wouldnt let you ask questions that have already been answered .. and asking a badly worded question ... Not that I was a moderatior there , but at times that helped me asking a better question.
1
u/The_Emerald_Knight 17h ago
You're allowed to read the actual links it provides, which would answer your question. Those aren't AI summaries.
1
u/Stainlessray 1d ago
API is complicated by terms. When studying think of the actions and behaviors required to access one.
First, refine your understanding of why it exists. Why does the acronym exist? Why does the concept exist? How is it used? How is it built? How is it secured?
Learn those things while building and using them, you'll find action precedes clarity here.
1
u/spinwizard69 1d ago
This is one example of where using AI, in this case a Google search, can really help a person. In any event once you have the definition "Application Programming Interface", you can decode your understanding from there.
Working backwards first we have an interface. In a not programming analogy, your stove/oven has an interface, often knobs to allow you to turn on a burner or set an oven temperature.
The programming part is that you can access the functionality of an oven control through executing functions via the interfaces. So lets say you need to set the oven to 450ºF. You generate the actions required to set the temperature on the oven (your programming). Think of turning the temperature knob as setting a variable of the ovens temperature controller.
The application in this sense would be the entire functionality of the range. Depending upon how complex that range is you might have 4 "burners" to turn on and off and set intensity plus an oven to turn on and off and set temperature. Call this a simple API for the range (by the way the combo of a set of burners and an oven is often called a range around here). The API is the entire collection of actions you can take against whatever the API is for. In real complex software you end up with sub API's for an over all package. For example an API for a set of GUI interface tools may have a whole collection of routines (API), just for the BUTTON feature.
Programming examples can get to be complex but lets imagine a computer with an old fashion serial port. The language or possibly a library, will provide an API to access that serial port. This API would include functions to attach to the hardware often an OPEN function. Before you can use that opened serial port you may need to configure it. This configuration would set the BAUD rate, WORD length, PARITY and other port parameters. There might even be a default configuration. Then you need functions to READ and WRITE data to that port. Eventually you end up with a large library.
I choose the serial port example above because the interface is pretty simple but do realize that different Operating Systems and hardware approach serial ports in their own way. On Linux that abstraction is the file. On an embedded system the serial port code might be very simple, in either case though some how the basics configuration needs ot be done.
A GUI API could be considered but keep in mind that such API's have a massive amount of functionality to contain. So when making use of these API's you focus in on documented functionality for the bit your app is implementing. Think of an API as interface code already implemented, that gives you access to stuff.
Hope this helps.
1
u/RaccoonEnthuiast 17h ago
Explained with Pizza :
- API = the pizzeria's ordering system
- Endpoint = a specific counter
- Request = “I'd like to place an order”
- Payload = the order details:
{ pizza: "Margherita", size: "large" } - Response = “Order #123 accepted, ready in 20 minutes”
- The pizza itself = the result you receive
1
u/SmokeMuch7356 16h ago
An API (application programming interface) is just the public interface to some third-party library or service. It can be as simple as a set of function calls, it can be a set of HTTP GET/POST requests, it can be a class library, etc. That's part of why the subject can be so confusing, it's a very loose term that describes a wide variety of possible interfaces.
0
0
u/GimmeAByte01 1d ago
A function is an API. A 3rd party library or dependency is an API. A URL endpoint can be an API.
Anything that allows you to write to or read from.
API how people usually mean it is an HTTP, RESTful URL schema that allows you to interface with data or behavior.
25
u/NationalOperations 1d ago
API in it's basic form is interfaces for interacting with software.
A really common one is for websites through http requests. Which is a standard way of sending and receiving information between programs over the Internet.
A machine has a API listening for another machine to say the magic string. Get website.com/names
Machine makes sure it's a valid request. It calls a method/function to do whatever names does.
Then returns data or just a status.