Skip to main content

Command Palette

Search for a command to run...

Understanding REST APIs: A Beginner-Friendly Guide

Updated
2 min read
Understanding REST APIs: A Beginner-Friendly Guide

Introduction

Modern web applications constantly communicate with servers to fetch or update data. For example, when you open a social media app or check the weather on your phone, your device sends a request to a server and receives information in return.

This communication usually happens through REST APIs.

In this article we will understand:

  • What a REST API is

  • How REST APIs work

  • Common HTTP methods used in REST APIs

  • A simple example using backend development

What is a REST API?

REST stands for Representational State Transfer.

A REST API is a way for applications to communicate with each other over the internet using HTTP requests.

Example request:

GET /users/1

Example response:

{
 "id": 1,
 "name": "Yuva"
}

The server sends data in JSON format.


Common HTTP Methods

GET

Used to retrieve data.

Example:

GET /users

POST

Used to create data.

POST /users

PUT

Used to update data.

PUT /users/1

DELETE

Used to remove data.

DELETE /users/1

Example Using Spring Boot

Example API in Java Spring Boot:

@GetMapping("/users/{id}")
public User getUser(@PathVariable int id) {
    return userService.getUserById(id);
}

This API returns user information based on the given ID.


Why REST APIs Are Important

REST APIs are widely used because they are:

  • Simple

  • Lightweight

  • Scalable

  • Easy to integrate

Most modern applications rely on REST APIs for communication between services.


Conclusion

REST APIs allow applications to communicate using HTTP methods like GET, POST, PUT, and DELETE.

Understanding REST APIs is essential for backend developers and anyone interested in web development.