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

Status Codes

200, 404, and friends.

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

Every response starts with a status code. It's a three digit number that says how the request went.

  • Every response has one
  • Three digits
  • How did it go?

Status code families

The first digit tells you the family. Two hundreds mean success. Three hundreds mean go somewhere else. Four hundreds mean the client made a mistake. And five hundreds mean the server had a problem.

FamilyMeaning
2xxsuccess
3xxredirect, look elsewhere
4xxclient mistake
5xxserver problem

Codes you will see often

Two hundred means OK. Two oh one means created, after a POST. Two oh four means done, with nothing to send back. Four hundred means bad request, like missing data. Four oh four means not found. And five hundred means the server crashed while handling the request.

CodeNameWhen
200OKit worked
201Createda new thing was made
204No Contentworked, nothing to return
400Bad Requestinvalid input
404Not Foundno such thing
500Internal Server Errorthe server failed

Seeing the status

Curl dash i shows the response headers, including the status line. Run it. Slash hello answers two hundred, with the text. Slash books doesn't exist in this app, so we get four oh four. Notice the content type header too. It says what kind of data the body holds.

HelloController.javajava
@RestController
public class HelloController {

    @GetMapping("/hello")
    public String hello() {
        return "Hello!";
    }
}
Output
$ curl -i localhost:8080/hello
HTTP/1.1 200
Content-Type: text/plain;charset=UTF-8

Hello!
$ curl -i localhost:8080/books
HTTP/1.1 404
Content-Type: application/json

{
  "timestamp":"2026-11-25T16:17:32.154Z",
  "status":404,
  "error":"Not Found",
  "path":"/books"
}
Also uses _curl.sh
curl -i localhost:8080/hello
curl -i localhost:8080/books

Summary

The status code says how a request went. Two hundreds are success, four hundreds are client mistakes, and five hundreds are server problems. Next, JSON.

Key takeaways
  • 2xx success
  • 4xx client mistake
  • 5xx server problem
Next up: JSON — the language of APIs