Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

fab5freddy

macrumors 65816
Original poster
Jan 21, 2007
1,206
7
Heaven or Hell
I have a kind of Newbie Question :

What exactly is an API ?

I am trying to learn some OO PHP and JavaScript
and am trying to understand what an API is
but am having a headache trying to figure it out!

I have already googled it and don't understand most
of the definitions i have found!

Please Help a Newbie!
 
I have a kind of Newbie Question :

What exactly is an API ?

I am trying to learn some OO PHP and JavaScript
and am trying to understand what an API is
but am having a headache trying to figure it out!

I have already googled it and don't understand most
of the definitions i have found!

Please Help a Newbie!

It is an Application Programming Interface.

Basically it is a way for a programmer to define an interface by exposing certain functions / classes / methods etc to other programmers so that they can interact with the application / library / operating system that the developer is making.
 
Ah, the lost art of explaining things clearly. That will give the OP an even bigger headache.

OP:

An API is the sum of the programming hooks a software library offers to programmers.
If you used a graphics library, for instance, the API for that would be the various different functions that library allows you to use in it.

Sometimes, API is also used in the singular, as in: one single function you can use in that library or system.

This is a gross oversimplification but should be good enough.
 
I have a kind of Newbie Question :

What exactly is an API ?

I am trying to learn some OO PHP and JavaScript
and am trying to understand what an API is
but am having a headache trying to figure it out!

I have already googled it and don't understand most
of the definitions i have found!

Please Help a Newbie!

Once upon a time, everything was written in assembly and everybody had to look at every piece of code to know what was going on. When programs started getting bigger, that didn't work so well. In instead, programmers used a technique called modularization- they split the programs up into lots of little tiny pieces that have to talk to each other. That way, you only need to know 1) the way your little piece works and 2) the way other little pieces can talk to your piece.

The Application Programming Interface is the list of ways that the program can communicate with other programs. It tells you *what* the program does so you don't need to know *how* it does it- you can just assume it's a little black box that works.

Think of it like driving a car. You don't necessarily need to know what happens when you hit the accelerator, all you know is that applying pressure to it makes you go faster. "hit the accelerator = go faster" is the API while the actual details of increasing flow into the cylinder are implementation details.
 
Once upon a time, everything was written in assembly and everybody had to look at every piece of code to know what was going on. When programs started getting bigger, that didn't work so well. In instead, programmers used a technique called modularization- they split the programs up into lots of little tiny pieces that have to talk to each other. That way, you only need to know 1) the way your little piece works and 2) the way other little pieces can talk to your piece.

The Application Programming Interface is the list of ways that the program can communicate with other programs. It tells you *what* the program does so you don't need to know *how* it does it- you can just assume it's a little black box that works.

Think of it like driving a car. You don't necessarily need to know what happens when you hit the accelerator, all you know is that applying pressure to it makes you go faster. "hit the accelerator = go faster" is the API while the actual details of increasing flow into the cylinder are implementation details.

Very well explained... even I could understand!
 
A very simple example of a function from an API would be something like this:

Code:
SDL_BlitSurface(myGraphic, NULL, background, NULL);


You can see (if you know what blit means) that this would put a graphic on a screen.

What you don't see is the mess and tangle of code that makes this simple function possible. All you know about is that function to load images onto the screen. The above code example is using SDL. There are other API's such as Direct X or OpenGL.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.