DEV Community

Cover image for What Is an API? A Simple Explanation
Mohammad Shahzeb Alam
Mohammad Shahzeb Alam

Posted on • Originally published at mdshahzebalam.hashnode.dev

What Is an API? A Simple Explanation

  • What Is an API

    API Stands For Application Programming Interface

  • In a Simple Words We Can Say That APIs are Tech Waiters. You Know What Does a Waiter Do Basically It Takes Your Order and Then Tells The Kitchen To Prepare and Then it Serves You .

  • So, Basically as Same API Works like If You are a Frontend Developer You Want Some Random Data For Your Project Do You Want Prepare A 50-100 Random Data For Yourself No.

  • So, There’s API Comes in you Just Have To Integrate in your Project and Boom There are 100s Of Data Which You Have’nt Write

  • Why Do We Need API

  • API Lets You Communicate With Other Softwares

  • It can Be any Softwares Like - Twilio Using Twilio You Integrate SMS Feature In your Project you Don’t Have to Write The Whole Program For The SMS Feature

  • Someone Have Alredy Done the HeavyLifting For you So you Don’t Have To

  • There is Authentication API Like - 0Auth

  • Types Of APIs

  • Rest APIs - Mostly and Widely Used

  • GraphQL APIs - It Is More flexible, You can ask for what you need

  • SOAP APis - Older, Used In Enterprises

  • How Does API Works

  • First You(Client) Sent The Request

  • Server (API Providers) It Process The Request

  • Then Response (Data) Comes Back in JSON or XML Format

    {
      "city": "New York",
      "temperature": "25°C",
      "condition": "Sunny"
    }
    
  • API Tools

These Tools are used To Test The API By Sending And Recieving The Data For The Project

  • Postman API - Commnoly Used API Tool In The Market

  • RestFox - It’s an Open Source API Tool

  • Hands On Example

    Let’s try a free Cat Facts API 🐱

fetch("https://catfact.ninja/fact")
  .then(response => response.json())
  .then(data => console.log(data));
Enter fullscreen mode Exit fullscreen mode

Like These You Sent The Request Through Code

And The Response Comes In JSON

{
  "fact": "Cats sleep for 70% of their lives.",
  "length": 35
}
Enter fullscreen mode Exit fullscreen mode

🎉 Boom! You just used your first API.

  • ## There are Lots Of Free APIs

You Can Use Them to Try Different Things

  • Cat Facts

  • OpenWeather

  • PokéAPI

Thanks For Reading My Article ❤️

Top comments (0)