4

I am studying docker/K8s and openstack. I keep coming across the terms CLI and API, but fail to understand exactly whats the difference between the two ? There were some other posts around this question, but none really clarified. Please post with example if possible.

Mayank Kakkar
  • 43
  • 1
  • 3
  • 1
    An API (application interface) is the description about and gateway of how a client and a service communicate together. Those are generic terms. – Daniel W. Jul 31 '20 at 12:28

1 Answers1

6

CLI is acronym for Command Line Interface. It's quite the opposite from GUI, Graphical User Interface, where the commands are usually done with a mouse.

CLI is a program which takes input in the form of commands and it executes on the device. Hope you are familiar with command prompts. There are multiple types of command prompts. In the command prompt, you enter a command and it will give you the output. For example, in command prompt if you enter ls command it will give you the list of files in the folder you tried to execute this command. Note the input to CLI is called "command(s)". In the context of the question, if you have installed docker, the simplest CLI example you can try is docker --help. In a GUI you would press a (?) button with your mouse to produce the same effect.

API is acronym for Application Programming Interface.

As in the acronym, it is an interface between the client and service. It will let the client talk with the server which expose endpoints. Clients hit these endpoints to get the data they need.

API's are usually exposed over http(s). One good example for API is facebook's developer API's.

https://graph.facebook.com/{your-user-id}
?fields=birthday,email,hometown
&access_token={your-user-access-token}

if you hit this API endpoint you will get the data. Of course you need to substitute in the values of your user-id and access token. To get the access token and play around with facebook api's refer here.

In the context of question, a simple API in docker will be /containers/json.

Most of the commands in docker are mapped to API. What this means is, even though you execute a command in the command prompt(or bash), it will get converted into an API call underneath. You can read more about this here.

Hope this answers your question.

Cheers.

jolammi
  • 492
  • 3
  • 16
SRIDHARAN
  • 1,196
  • 1
  • 15
  • 35