REST API Explained with Simple Example

If you’ve spent any time exploring software development, web applications, or data-driven projects, you’ve likely come across the term REST API. But what exactly is it? How does it work? And why is it such a critical part of modern web and app development?

REST API Explained with Simple Example

In this beginner’s guide, we’ll break down REST APIs in simple terms, use relatable analogies, walk through a real-world example, and help you understand how they function in your everyday digital interactions. Let’s dive in!

What is an API?

First, let’s start with the term API.

API stands for Application Programming Interface. It’s a set of rules that allows two software programs to communicate with each other.

Imagine you’re at a restaurant:

  • You (the customer) are the application.
     
  • The kitchen is the server.
     
  • The waiter is the API.
     

You give your order to the waiter, who brings it to the kitchen. The kitchen prepares your food and hands it back to the waiter, who delivers it to your table. You never directly interact with the kitchen—you rely on the waiter to bridge the gap.

Similarly, in the software world:

  • You make a request to an API.
     
  • The API talks to the server.
     
  • The server returns data back to you.
     

What is a REST API?

Now that we understand APIs, let’s explore what REST means.

REST stands for REpresentational State Transfer. It’s a set of rules and principles for building APIs.

REST API is an API that follows the REST architectural style, using standard HTTP methods to perform actions.

It’s called stateless, meaning:

  • Every request is treated independently.
     
  • The server doesn’t remember previous requests from the same user.
     

REST APIs are:

  • Scalable
     
  • Fast
     
  • Widely used (Google, Facebook, Twitter, etc.)

Real-Life Example of REST API

Let’s say you’re using a weather app on your phone. You want to check the weather in Delhi.

Here’s what happens in the background:

1. You tap “Check Weather.”

The app sends a GET request to a weather REST API endpoint like:

arduino
CopyEdit
https://api.weather.com/current?city=Delhi

2. The API talks to the weather database and fetches current data.

The API sends back a JSON response like:
json
CopyEdit
 

Copy Code

{

  "city": "Delhi",

  "temperature": "36°C",

  "condition": "Partly Cloudy"

}

1. The app displays this on your screen.

2. You’ve just interacted with a REST API—without even knowing it!

Key Concepts in REST API

To understand REST APIs better, here are some key concepts:

1. Resources

In REST, everything is considered a resource. A resource could be:

  • A user
     
  • A product
     
  • A post
     
  • A city’s weather
     

Resources are identified using URLs (also called endpoints).

Example:

arduino

CopyEdit

https://api.example.com/users

This might return a list of all users.

2. HTTP Methods

REST APIs use standard HTTP methods to interact with resources.

MethodPurposeExample
GETRead dataGet user info
POSTCreate dataCreate a new blog post
PUTUpdate dataUpdate a product’s price
DELETEDelete dataRemove a comment

Example:

  • GET /users → Get all users
     
  • GET /users/1 → Get user with ID 1
     
  • POST /users → Create a new user
     
  • PUT /users/1 → Update user with ID 1
     
  • DELETE /users/1 → Delete user with ID 1
     

3. JSON Format

REST APIs usually return data in JSON format, which is easy to read and write.

Sample JSON Response:

json

CopyEdit

Copy Code

{

  "id": 101,

  "name": "John Doe",

  "email": "john@example.com"

}

You can access each property individually, like name or email.

4. Endpoints

An endpoint is the URL where a resource can be accessed.

Example endpoint for an e-commerce REST API:

nginx

CopyEdit

GET https://api.shop.com/products/123

This might return:

json

CopyEdit

Copy Code

{

  "product_id": 123,

  "name": "Wireless Mouse",

  "price": 899

}

Step-by-Step: How to Use a REST API

Let’s walk through how a beginner might use a public REST API like JSONPlaceholder (a free test API).

Step 1: Open a browser or API tool (like Postman)

Go to:

arduino

CopyEdit

https://jsonplaceholder.typicode.com/users

Step 2: You’ll get a response like:

json

CopyEdit

Copy Code

[

  {

    "id": 1,

    "name": "Leanne Graham",

    "email": "Sincere@april.biz"

  },

  ...

]

This is a REST API giving you a list of users.

Step 3: Try another endpoint:

arduino

CopyEdit

https://jsonplaceholder.typicode.com/users/1

It returns user ID 1’s data.

REST API Use Cases

Here are some everyday examples of REST APIs in action:

PlatformREST API Use Case
TwitterPost a tweet, fetch timeline, follow users
Google MapsGet directions, place data, distance matrix
YouTubeSearch videos, fetch video details
InstagramGet media, post photos, user profile data
E-commerce SitesProduct listings, order processing, payments

REST vs SOAP: What's the Difference?

FeatureRESTSOAP
FormatMostly JSONXML
SimplicitySimple and easyComplex and rigid
SpeedFasterSlower
UsageWidely used in modern appsUsed in enterprise apps

Conclusion: For most modern web and mobile apps, REST is the preferred API style.

How Developers Use REST APIs in Projects

1. Frontend Developer:

  • a. Uses APIs to fetch data from the backend.
  •  
  • b. Displays info on web pages using JavaScript frameworks (React, Angular).
     

2. Backend Developer:

  • a. Builds REST APIs using Python, Node.js, Java, etc.
     
  • b. Connects them to databases.
     

3. Mobile Developer:

  • a. Uses REST APIs in Android/iOS apps to sync data.
     

Building REST APIs (Optional for Advanced Learners)

As a beginner, you’ll mostly use REST APIs. But here’s a peek into how they’re built:

Using Python (Flask):

python

CopyEdit

from flask import Flask, jsonify

Copy Code

app = Flask(__name__)

@app.route('/greet')

def greet():

    return jsonify({'message': 'Hello from REST API!'})

if __name__ == '__main__':

    app.run()

This creates a REST API with one endpoint: /greet.

Visit http://localhost:5000/greet and you'll see:

json

CopyEdit

{"message": "Hello from REST API!"}

Learning REST API with Uncodemy

To truly master REST APIs—from consuming them to building your own—you need practical training.

✨ Recommended: Full Stack Developer Course by Uncodemy

This course covers:

  • a. REST API basics
     
  • b. Hands-on with Postman and JSON
     
  • c. Consuming APIs in front-end frameworks
     
  • d. Creating APIs with Node.js or Django
     
  • e. Real-time projects like weather apps, e-commerce sites, and blogs
     

👨‍🏫 Why choose Uncodemy?

  • a. Live sessions with industry experts
     
  • b. Real projects and assignments
     
  • c. Career support with job interviews
     
  • d. Certification on completion
     

📌 Explore the REST API module inside the Full Stack Developer Course on Uncodemy’s Website

Conclusion

To sum up, REST APIs are the bridge between your application and the data you want to work with. Whether you're displaying weather updates, fetching user profiles, or posting comments, REST APIs make it all possible—smoothly and efficiently.

By understanding REST basics, methods, and how endpoints work, you’ll gain the confidence to build or use APIs in real projects. And if you're aiming to become a full stack developer, data scientist, or app developer, learning REST APIs is a must-have skill.

Keep practicing, use tools like Postman, and explore public APIs to sharpen your skills.

Placed Students

Our Clients

Partners

...

Uncodemy Learning Platform

Uncodemy Free Premium Features

Popular Courses