← Back to Questions
Spring Boot

Difference between PUT and POST?

Learn Difference between PUT and POST? with simple explanations, real-time examples, interview tips and practical use cases.

Difference Between PUT and POST in REST API

PUT and POST are HTTP methods used in REST APIs.

Both methods send data from client to server, but they are used for different purposes.

  • POST → Create new resource
  • PUT → Update existing resource

Simple Definition

POST creates new data, while PUT updates existing data.

What is POST?

POST method is mainly used to:

  • Create new resources
  • Submit form data
  • Send data to server

Example

POST /api/courses

This creates a new course.


What is PUT?

PUT method is mainly used to:

  • Update existing resources
  • Replace existing data

Example

PUT /api/courses/1

This updates course with ID 1.


Main Difference Table

Feature POST PUT
Purpose Create new resource Update existing resource
Idempotent No Yes
Multiple Requests May create multiple records Produces same result
Resource ID Usually generated by server Usually provided in URL
Usage Create operation Update operation

Real-Time Example

Suppose we are developing Dhanish Empower.

Create New Course Using POST

POST /api/courses

Request Body

{
  "name": "Spring Boot",
  "price": 999
}

Server creates a new course.


Update Existing Course Using PUT

PUT /api/courses/1

Request Body

{
  "name": "Spring Boot Advanced",
  "price": 1499
}

Server updates course with ID 1.


What is Idempotent?

Idempotent means:

Multiple identical requests produce the same result.

PUT is Idempotent

Example:

PUT /api/courses/1

Sending same request multiple times:

  • Updates same course repeatedly
  • Final result remains same

Therefore PUT is idempotent.


POST is Not Idempotent

Example:

POST /api/courses

Sending same request multiple times:

  • Creates multiple new courses
  • Result changes every time

Therefore POST is not idempotent.


Spring Boot POST Example

@PostMapping
public Course saveCourse(
        @RequestBody Course course) {

    return courseService.save(course);
}

Used to create new course.


Spring Boot PUT Example

@PutMapping("/{id}")
public Course updateCourse(
        @PathVariable Long id,
        @RequestBody Course course) {

    return courseService.update(id, course);
}

Used to update existing course.


HTTP Status Codes

Operation Common Status Code
POST Create 201 Created
PUT Update 200 OK

URL Structure Difference

POST

POST /api/courses

Resource ID usually not included.


PUT

PUT /api/courses/1

Resource ID usually included.


When to Use POST?

  • User Registration
  • Create Orders
  • Add New Courses
  • Payment Creation

When to Use PUT?

  • Update User Profile
  • Update Course Details
  • Update Payment Status
  • Edit Existing Records

Production-Level Importance

Correct usage of PUT and POST is very important in:

  • REST API design
  • Microservices architecture
  • Cloud-native applications
  • Frontend-backend communication
  • Distributed systems

Proper API design improves scalability and maintainability.


Common Mistake

Many beginners use POST for updates.

Best practice:

  • POST → Create
  • PUT → Update

Interview Answer

POST method is used to create new resources, while PUT method is used to update existing resources.

PUT is idempotent because repeated requests produce the same result, whereas POST is not idempotent because repeated requests may create multiple resources.


Short Interview Answer

POST creates new data, while PUT updates existing data.


Frequently Asked Questions

Which method is used for creation?

POST.

Which method is idempotent?

PUT.

Can PUT create data?

Technically yes in some APIs, but mainly used for updates.

Why is POST not idempotent?

Because repeated requests may create multiple resources.

Which method is best for updating resources?

PUT.


Conclusion

PUT and POST are important HTTP methods in REST APIs.

POST is mainly used for creating new resources, while PUT is used for updating existing resources.

Understanding their differences is essential for designing scalable and production-ready REST APIs.

Why this Spring Boot question is important?

This interview question helps candidates understand real-time backend development concepts, practical problem solving, coding fundamentals, system design basics and production-ready application behavior.

Practice this question carefully for Java backend roles, Spring Boot developer interviews, microservices interviews, company interviews and full-stack developer preparation.

About the Author

Naresh Kumar is a Senior Java Backend Engineer with experience building enterprise applications using Java, Spring Boot, Microservices, Docker, Kubernetes and Cloud technologies.