AI Hints
Home›Spring Boot Tutorial›HTTP Methods, Status Codes and JSON
Spring Boot · Lesson 10 of 120

HTTP Methods

GET, POST, PUT, DELETE.

⏱ 2 min read▶ Video at 12:18🎓 Free
Watch this lesson in the Spring Boot courseWatch on YouTube ↗Full Spring Boot course

Every request has a method. The method says what the client wants to do. Read something, create something, change it, or delete it.

  • Every request has a method
  • Read or create
  • Change or delete

The four main methods

GET reads data, like the list of books. POST creates something new, like a new book. PUT replaces something that already exists, like updating a book. And DELETE removes something. Your browser's address bar always sends GET.

MethodMeaningExample
GETreadget all books
POSTcreateadd a new book
PUTreplace / updatechange book 3
DELETEremovedelete book 3

Same path, different methods

Both methods use the same path, slash books. Get Mapping answers GET requests. Post Mapping answers POST requests. With curl, dash X picks the method, and GET is the default. Run it. GET lists, and POST adds. But we have no method for DELETE, so Spring answers four oh five, method not allowed.

BookController.javajava
@RestController
public class BookController {

    @GetMapping("/books")
    public String list() {
        return "Here are all the books";
    }

    @PostMapping("/books")
    public String add() {
        return "A new book was added";
    }
}
Output
$ curl localhost:8080/books
Here are all the books
$ curl -X POST localhost:8080/books
A new book was added
$ curl -X DELETE localhost:8080/books
{
  "timestamp":"2026-11-25T16:17:29.471Z",
  "status":405,
  "error":"Method Not Allowed",
  "path":"/books"
}
Also uses _curl.sh
curl localhost:8080/books
curl -X POST localhost:8080/books
curl -X DELETE localhost:8080/books

Safe and unsafe

GET should never change anything on the server. It only reads. That's why it's safe to repeat, or to refresh a page. POST, PUT, and DELETE change data, so clients must be careful with them.

keyvalue
GETonly reads, safe to repeat
POSTcreates
PUTreplaces
DELETEremoves

Summary

The HTTP method says what to do: GET reads, POST creates, PUT replaces, and DELETE removes. Spring has a mapping annotation for each. Next, status codes.

Key takeaways
  • GET, POST
  • PUT, DELETE
  • curl -X METHOD
Next up: Status Codes — 200, 404, and friends