API Communication

270 views

I know how Web-APIs work, but how do APIs between two apps on one system work fundamentally?
If I write program A, that exposes an API X, and an Application B that calls on that API, how does that work from a compiler, OS and hardware standpoint?

In: 5

9 Answers

Anonymous 0 Comments

This is not easy to translate for ELI5 but there are many methods and I’m just going to cover two common ones.

UNIX-like operating systems offer “sockets” which are akin to postal mail. You can address some things within the building or business (i.e. file or private TCP/IP port) and others globally (public TCP/IP port) and pass messages via many forms (protocols, such as HTTP or SSH) just as physical mail can be a letter or package. This would involve C standard function calls to read and write sockets: `socket`, `bind`, `connect`.

Another mechanism is process execution where a program calls another program and reads its response back via a “pipe” such as “standard output”. In code this would be a call to some function like `exec`.

Fundamentally each of these are [message passing](https://en.wikipedia.org/wiki/Message_passing).

You are viewing 1 out of 9 answers, click here to view all answers.