Java · Advanced level

Advanced level · Module 4: HTTP Clients and JSON in Java · Lesson 1 of 4

HTTP Fundamentals

Understand requests, responses, methods, headers and status codes, the language every web API speaks.

In this lesson you will

  • Describe HTTP methods, headers and status code classes
  • Inspect real requests and responses with a tool

Key concepts

GET, POST, PUT, DELETEheadersstatus codes 2xx/4xx/5xxidempotency

The lesson

HTTP is a request–response protocol. A client sends a method, a URL, headers and sometimes a body; the server answers with a status code, headers and a body. GET reads, POST creates, PUT replaces, PATCH updates part of a resource and DELETE removes.

Status codes group into classes: 2xx success (200 OK, 201 Created), 4xx client errors (400 Bad Request, 401 Unauthorized, 404 Not Found) and 5xx server errors (500, 503). Your code must check the status before trusting the body.

GET, PUT and DELETE should be idempotent: repeating them has the same effect as doing them once. That property matters when deciding whether a failed request can safely be retried.

Step by step

  1. Send GET requests to a test API with curl or a browser.
  2. Inspect the status code and headers.
  3. Send a POST with a JSON body.
  4. Trigger a 404 and a 400 and read the responses.

Practice activity

Document five requests to a practice API: method, URL, headers, body, status code and what the response means.

Expected result: A correct table of five requests, including at least one 4xx response explained.

Check your understanding

  1. Which status code class means the client made an error?

    Show answer

    4xx.

  2. Is POST normally idempotent?

    Show answer

    No; repeating a POST can create duplicate resources.

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.