Sobes.tech
Senior

HTTP methods POST, PUT, and PATCH — which have you used and in what cases?

sobes.tech AI

Answer from AI

POST is used to create new resources on the server. For example, when registering a user, a POST request with data is sent.

PUT is used for completely updating an existing resource — it replaces its content entirely. For example, updating a user's profile completely.

PATCH is used for partial updates of a resource, when only specific fields need to be changed without affecting others.

Example in Java using Spring:

@PostMapping("/users")
public ResponseEntity<User> createUser(@RequestBody User user) {
    // creation logic
}

@PutMapping("/users/{id}")
public ResponseEntity<User> updateUser(@PathVariable Long id, @RequestBody User user) {
    // full update logic
}

@PatchMapping("/users/{id}")
public ResponseEntity<User> patchUser(@PathVariable Long id, @RequestBody Map<String, Object> updates) {
    // partial update logic
}