Application Program Interfaces
Just as drivers provide a way for applications to make use of hardware subsystems without having to know every detail of the hardware's operation, application program interfaces (APIs) let application programmers use functions of the computer and operating system without having to directly keep track of all the details in the CPU's operation. Let's look at the example of creating a hard disk file for holding data to see why this can be important.
A programmer writing an application to record data from a scientific instrument might want to allow the scientist to specify the name of the file created. The operating system might provide an API function named MakeFile for creating files. When writing the program, the programmer would insert a line that looks like this:
In this example, the instruction tells the operating system to create a file that will allow random access to its data (signified by the 1 — the other option might be 0 for a serial file), will have a name typed in by the user (%Name) and will be a size that varies depending on how much data is stored in the file (signified by the 2 — other options might be zero for a fixed size, and 1 for a file that grows as data is added but does not shrink when data is removed). Now, let's look at what the operating system does to turn the instruction into action.
The operating system sends a query to the disk drive to get the location of the first available free storage location.
With that information, the operating system creates an entry in the file system showing the beginning and ending locations of the file, the name of the file, the file type, whether the file has been archived, which users have permission to look at or modify the file, and the date and time of the file's creation.
Because the programmer has written the program to use the API for disk storage, the programmer doesn't have to keep up with the instruction codes, data types and response codes for every possible hard disk and tape drive. The operating system, connected to drivers for the various hardware subsystems, deals with the changing details of the hardware. The programmer must simply write code for the API and trust the operating system to do the rest. Unfortunately, access to software via APIs may offer hackers an opportunity to use the application to their benefit and perhaps gain other access to the computer. That doesn't mean APIs are bad, but developers must make sure to avoid creating vulnerabilities and to patch them when they're identified.
Still, APIs have become one of the most hotly contested areas of the computer industry in recent years. Companies realize that programmers using their API will ultimately translate this into the ability to control and profit from a particular part of the industry. Developers know that providing applications like readers or viewers to the public at no charge will encourage consumers to use their software, although they may expect other developers to pay royalties to allow their software to provide the functions requested by the consumers. Many others make their APIs freely available to the public.