eli5: What is the difference between a Protocol and API?


eli5: What is the difference between a Protocol and API?

In: 0

A protocol is basically a set way of doing something.

When you write a letter, you start with a salutation (“dear X”), the body, then an ending (“sincerely”) and your name. That’s a protocol.

When you cross the street, you go to a crosswalk. If there is a light you wait for it to signal for you to cross. If not, you look both ways and wait for a safe time to cross. That’s a protocol.

An API is basically a collection of protocols that allow one piece of software to communicate with another without needing to understand the specifics.

One analogy is how a car works. In a car you have a break pedal on the left, a gas pedal on the right, and a steering wheel. All cars, trucks, vans, what have you, have this set up and a person driving them only needs to know how to accelerate, brake, and steer using them. How the car actually works (how it translates you turning the steering wheel into turning the tires, how it accelerates when you press the gas or brakes when you press the brake pedal) is irrelevant to you. You can operate it without this knowledge.

An API is a set of functions that an application exposes to other applications.

A protocol describes the mechanism by which those applications communicate.

An API will often specify the protocol(s) required to interact with the system. For example a website might say, this is our API, you can call this getWeather method to request the current weather for the city provided. But the documentation will also say, this is a REST API, you must use the Hyper Text Transfer Protocol to send requests. And if you don’t know what that is, you need to refer to the HTTP specification to know how to structure your requests, and what responses to expect.