What is REST API ?

βœ… Introduction to REST API

What is REST API?
A REST API (Representational State Transfer Application Programming Interface) is a set of rules that allows different software applications to communicate with each other over the internet using the HTTP protocol.

When you use an app on your phone or open a website in your browser, much of the data shown to you is fetched from a remote server through a REST API.


πŸ‘¨β€πŸ’» Why Do We Use REST APIs?

When you visit a website, you interact with visual elements like buttons, forms, or images β€” this is called the User Interface (UI).
Similarly, REST APIs provide a way for applications to interact with each other, just like humans interact with a UI.

For example:

  • A mobile app fetches user data from a cloud server

  • A web app stores form data into a database

  • An app shows weather updates by fetching data from a weather API


πŸ” How REST API Works

Let’s break down how REST API works in simple steps:

  1. Client (mobile app, browser, etc.) sends a request to a specific API endpoint

  2. The server receives the request and processes it

  3. The server responds with data, usually in JSON format

  4. The client displays the data to the user

Example:

sh
GET https://api.example.com/users

Response:

sh
[
{ “name”: “Vishal”, “email”: “[email protected]” }
]

🌍 HTTP Methods Used in REST APIs

Method Description Example Use
GET Fetch data /users β†’ Get all users
POST Create new data /users β†’ Add a user
PUT Update existing data completely /users/1 β†’ Update user 1
PATCH Update part of the data /users/1 β†’ Update name
DELETE Delete existing data /users/1 β†’ Delete user 1

🧠 Real-Life Analogy of REST API

Imagine ordering food at a restaurant:

  • You = Client

  • Waiter = REST API

  • Kitchen = Server

  • Menu = API Documentation

  • Order = Request

  • Food = Response

You tell the waiter what you want β†’ waiter goes to the kitchen β†’ brings back your food.


🌐 Benefits of REST API

  • Platform-independent (works with web, mobile, desktop)

  • Lightweight (uses HTTP & JSON)

  • Scalable and modular

  • Easily consumed by frontend and backend developers


πŸ” What is REST API in Login & Social Authentication

REST APIs play a vital role in login systems like Facebook Login or Google Sign-In.

Here’s how the OAuth login flow using REST API works:

  1. User clicks “Log in with Google”

  2. App redirects to Google login

  3. User enters credentials and grants permission

  4. Google sends an authorization code back to the app

  5. App sends this code to the backend

  6. Backend sends a REST API request to Google’s API to get an access token

  7. Google sends back an access token

  8. Backend uses the token to fetch user data via another REST API call

 

πŸ”„ REST API Request & Response Lifecycle

sh
[ Client (App/Browser) ]
|
Sends Request
↓
[ Server (API Endpoint) ]
|
Processes Request
↓
Sends Response
|
[ Client Receives & Displays Data ]

What is Rest Api

Scroll to Top