
Let’s think it through · Start with a story
A girl orders at a counter without going into the kitchen. A robot explains that programs can request functionality through an agreed interface, too.
Break down the process
- Agree on inputsWhat is needed and which parameters
- Call the interfaceSubmit them in the agreed format
- Run the functionHandle the work internally
- Agree on outputsReturn a result or an error
An API is an agreed interface that lets one program use another part’s functionality.
Like a menu, it tells you what you can order, what information to provide, and what result to expect. Network APIs often use requests and responses, but an API can also exist inside a program or library.
A clear interface means callers do not need to know every detail of the implementation.
Your turn
If an interface expects a city ID but you submit an image, can the service be expected to guess that you want a weather report?
Have an answer? Click to see the explanation
No. The caller must follow the input format, and the service should validate it and return an appropriate error.
Takeaway
An API is an agreed interface that lets one program use another part’s functionality.
Try covering the diagram and explaining each step to someone at home. If a step is hard to explain, go back and look at that card again.