How are APIs made?

08 Nov.,2023

 

In practice, an API is simply the documented interface of some existing (reference or sample) implementation.

In theory, one could design an API in the abstract. Practically doing that without any implementation is a costly mistake (because without implementation there are lot of details you won't think about).

Read also about undefined behavior.

Notice that pure standard C++11 does not offer much about interacting with the outside world: the C++11 standard does not know about directories, keyboard, mices, screens, sounds, networks, GUIs etc. Your operating system probably have more relevant additional specific libraries. Learn more about POSIX which could be understood as a standardized API for operating system services (sadly, some proprietary OSes sold by MicroSoft are not natively POSIX compliant; it is rumored that you might buy some POSIX-like interface to their Windows OS, which have their own Windows API).

If you want to implement something, you'll need to know well the target platform, i.e. the operating system that you want to support. For Linux, start reading Advanced Linux Programming, intro(2), syscalls(2), intro(3), etc... and study in details the source code of free software implementations (see e.g. sourceforge ...) relevant to your goal.

If you want to be cross-platform (e.g. be able to compile the same code on Linux and on MacOSX), better use & leverage on existing cross-platform frameworks like Qt or POCO, or (if they are relevant for your needs) libsdl or SFML. These frameworks are using some operating system specific APIs (and try to define some common abstraction above them).

PS. In practice, designing a good API is a difficult art. Well documenting it is essential. If possible, make your implementation free software, and try to get advices and help about it.

For more information API Raw Material Suppliers, please get in touch with us!