What the fetch() is an API ?
Tags: api, explained, webdev, beginners
Published: 2020-09-07 16:03:54

You're familiar with the concept of modularity from OOPS, right? So, my introduction is not in this post. :laughing:

{% post dsp9107/how-did-i-start-my-tech-journey-53ia %}

---

# Introduction

> An application programming interface (API) is a computing interface which defines interactions between multiple software intermediaries. It defines the kinds of calls or requests that can be made, how to make them, the data formats that should be used, the conventions to follow, etc. - [Wikipedia](https://en.wikipedia.org/wiki/API)

There's this fuss about APIs. Everyone has their own definition of what an API is or at least what it's like. But, let me tell you this. Don't trust anyone :hear_no_evil:

# Contents

- [Introduction](#introduction)
- [Explanation](#explanation)
  - [The Dictionary Analogy](#the-dictionary-analogy)
  - [The Restaurant Analogy](#the-restaurant-analogy)
- [Conclusion](#conclusion)
- [References](#references)
- [Further Reads](#further-reads)

# Explanation

There is a [plethora](https://www.google.com/search?q=plethora) of analogies. Let's break some of them down.

### The Dictionary Analogy

This one's quite right, that an API is kinda like a dictionary. But, according to [Wikipedia](https://en.wikipedia.org/wiki/Dictionary#Types), there are more than 15 types of dictionaries.

![there it is](https://media.giphy.com/media/25OBBnY9j1uiVDV4lJ/giphy.gif)

So, it's not just **a** dictionary. It's a **bilingual** dictionary; the one we use when we travel to a foreign country.

The dictionary tells us **how to communicate** with a person who does not understand the language we speak.

This is very much similar to the articles we find on Google when we search for "what does it mean when a dog wags its tail in a clockwise manner". Those articles tell us **how to understand** the dog. :grin:

### The Restaurant Analogy

This one might hold true for an [MVC architecture](https://developer.chrome.com/apps/app_frameworks) but not for an API. Let's see why not.

What do we do when we go to a restaurant? Do we just walk straight into the kitchen and tell the chef what we would like to have for dinner? Well, I certainly don't. :laughing:

The expectations from us guests are, that we let the waiter know what we would like to have and he will take our order and forward it to the chef. The waiter's job is to keep a track of and serve the orders.

![waiter](https://media.giphy.com/media/l41lQKzFg8T8p7oas/giphy.gif)

Here, the waiter is just a middleman. The actual message is the dish(es) we order. That is the request which we make.

*Coming back to the internet.*

```bash
GET https://pokeapi.co/api/v2/pokemon/jigglypuff
```

This is a request. But how could we know that URL?

How do you know that the restaurant serves noodles?

![pokeroll](https://media.giphy.com/media/DRfu7BT8ZK1uo/giphy.gif)

**The Menu Card** :tada:

That is the API. We can select which dish would we like and tell the waiter to get it served for us. *Remember, he's not the one who cooks it.*

Similarly, [this](https://pokeapi.co/docs/v2#pokemon) is an API. It tells us how to talk to the Pokedex and how will it respond to us.

```bash
GET https://pokeapi.co/api/v2/pokemon/{id or name}/
```

Just like that URL has `{id or name}` in it to tell us that either we could pass the `name` of the pokemon in the URL or its `id`, some restaurants also provide us with methods to order, either we could call them or walk-in.

# Conclusion

![happy ash](https://media.giphy.com/media/amrNGnZUeWhZC/giphy.gif)

Documentation is important. Developers actually use those. :grin:

# References

- [Application Programming Interface](https://en.wikipedia.org/wiki/API)
- [MVC Architecture](https://developer.chrome.com/apps/app_frameworks)
- [Pokedex](https://www.pokemon.com/us/pokedex)
- [PokeAPI v2](https://pokeapi.co/docs/v2)

# Further Reads

- [Understanding a Simple Express Server App | Node.js](https://dev.to/dsp9107/understanding-the-simple-express-app-node-js-10j5)
- [Interacting with a Simple Express Server App | Postman](https://dev.to/dsp9107/interacting-with-the-simple-express-app-using-postman-594m)
- ["is a plethora" or "are a plethora"?](https://english.stackexchange.com/questions/103176/there-is-a-plethora-or-there-are-a-plethora)