REST API Tutorial

 🚀 Introduction

REST APIs allow different applications to communicate with each other.

Each API request uses a specific HTTP Method based on the action:

MethodActionMeaning
GETReadFetch data from server
POSTCreateAdd new data
PUTUpdateReplace existing data
PATCHModifyModify part of existing data
DELETERemoveDelete data

We will use live working APIs from:

👉 https://restful-api.dev/



📥 1. GET — Retrieve / Read Data

➤ Example 1: Fetch multiple items using IDs

🔗 API URL:

https://api.restful-api.dev/objects?id=4&id=6&id=10

🟦 cURL Example (GET)

curl --location 'https://api.restful-api.dev/objects?id=4&id=6&id=10' \ --data ''

📌 Example Response:

[
    {
        "id": "4",
        "name": "Apple iPhone 11, 64GB",
        "data": {
            "price": 389.99,
            "color": "Purple"
        }
    },
    {
        "id": "6",
        "name": "Apple AirPods",
        "data": {
            "generation": "3rd",
            "price": 120
        }
    },
    {
        "id": "10",
        "name": "Apple iPad Mini 5th Gen",
        "data": {
            "Capacity": "64 GB",
            "Screen size": 7.9
        }
    }
]

➤ Example 2: Fetch a specific object by ID

🔗 API URL:

https://api.restful-api.dev/objects/ff8081819782e69e019a41218336270d

🟦 cURL Example (GET)

curl --location 'https://api.restful-api.dev/objects/ff8081819782e69e019a41218336270d' \ --data ''

📌 Example Response:

{
    "id": "ff8081819782e69e019a41218336270d",
    "name": "Apple Testing update MacBook Pro 16",
    "data": {
        "year": 2019,
        "price": 1849.99,
        "CPU model": "Intel Core i9",
        "Hard disk size": "1 TB"
    }
}

✅ GET only retrieves data, it never modifies.



➕ 2. POST — Create Data

📌 Used when you want to add a new record into server/database.

🔗 API URL:

https://api.restful-api.dev/objects

📦 Request Body:

{ "name": "Apple Testing MacBook Pro 16", "data": { "year": 2019, "price": 1849.99, "CPU model": "Intel Core i9", "Hard disk size": "1 TB" } }

🟦 cURL Example (POST)


curl --location 'https://api.restful-api.dev/objects' \ --header 'Content-Type: application/json' \ --data '{ "name": "Apple Testing MacBook Pro 16", "data": { "year": 2019, "price": 1849.99, "CPU model": "Intel Core i9", "Hard disk size": "1 TB" } }'

📌 Example Response:
{
    "id": "ff8081819782e69e019a44762e9b2aee",
    "name": "Apple Testing MacBook Pro 16",
    "createdAt": "2025-11-02T12:06:27.227+00:00",
    "data": {
        "year": 2019,
        "price": 1849.99,
        "CPU model": "Intel Core i9",
        "Hard disk size": "1 TB"
    }
}

✅ POST creates a new record and server generates an ID.



🔄 3. PUT — Update (Replace everything)

📌 Used to replace the entire object with new values.

🔗 API URL:

https://api.restful-api.dev/objects/ff8081819782e69e019a41218336270d

📦 Request Body (full update):

{ "name": "Apple Testing update MacBook Pro 16", "data": { "year": 2019, "price": 1849.99, "CPU model": "Intel Core i9", "Hard disk size": "1 TB" } }

🟦 cURL Example (PUT)

curl --location --request PUT 'https://api.restful-api.dev/objects/ff8081819782e69e019a41218336270d' \ --header 'Content-Type: application/json' \ --data '{ "name": "Apple Testing update MacBook Pro 16", "data": { "year": 2019, "price": 1849.99, "CPU model": "Intel Core i9", "Hard disk size": "1 TB" } }'

📌 Example Response:

{
    "id": "ff8081819782e69e019a41218336270d",
    "name": "Apple Testing update MacBook Pro 16",
    "updatedAt": "2025-11-02T12:08:01.394+00:00",
    "data": {
        "year": 2019,
        "price": 1849.99,
        "CPU model": "Intel Core i9",
        "Hard disk size": "1 TB"
    }
}

✅ PUT replaces the entire existing object.



✏ 4. PATCH — Update (Partial)

📌 Used when you want to update only one field, not the entire object.

🔗 API URL:

https://api.restful-api.dev/objects/ff8081819782e69e019a41218336270d

📦 Request Body (only updating name):

{ "name": "Apple MacBook Pro 16 (Updated Name)" }

🟦 cURL Example (PATCH)

curl --location --request PATCH 'https://api.restful-api.dev/objects/ff8081819782e69e019a41218336270d' \ --header 'Content-Type: application/json' \ --data '{ "name": "Apple MacBook Pro 16 (Updated Name)" }'

📌 Example Response:

{
    "id": "ff8081819782e69e019a41218336270d",
    "name": "Apple MacBook Pro 16 (Updated Name)",
    "updatedAt": "2025-11-02T12:09:19.622+00:00",
    "data": {
        "year": 2019,
        "price": 1849.99,
        "CPU model": "Intel Core i9",
        "Hard disk size": "1 TB"
    }
}

✅ PATCH updates only the provided field, keeping the rest unchanged.



🗑️5. DELETE — Remove Data

📌 Used to delete a record from server/database.

🔗 API URL:

https://api.restful-api.dev/objects/ff8081819782e69e019a41218336270d


🟦 cURL Example (DELETE)

curl --location --request DELETE 'https://api.restful-api.dev/objects/ff8081819782e69e019a44762e9b2aee' \ --data ''


📌 Example Response:

{
    "message": "Object with id = ff8081819782e69e019a44762e9b2aee has been deleted."
}

⬅️ After DELETE, fetching the same ID will return not found.



🎯 Summary: When to use what?

MethodCRUD ActionUsage
GETReadFetch existing data
POSTCreateInsert new record
PUTUpdateReplace full object
PATCHUpdateModify some fields
DELETEDeleteRemove object

🎉 Final Notes

These APIs are great for practice using:

  • Postman

  • Swagger

  • Java / Python / JavaScript API projects

You can now confidently use REST API methods in your applications.


💼 Professional Support Available

If you are facing issues in real projects related to enterprise backend development or workflow automation, I provide paid consulting, production debugging, project support, and focused trainings.

Technologies covered include Java, Spring Boot, PL/SQL, Azure, and workflow automation (jBPM, Camunda BPM, RHPAM).




Comments

Popular posts from this blog

jBPM Installation Guide: Step by Step Setup

Scopes of Signal in jBPM

OOPs Concepts in Java | English | Object Oriented Programming Explained