Rana Maninder Singh
Lesson 2 of 12API & Integration Development

HTTP Fundamentals

Lesson opener

In one line: HTTP methods say what kind of operation you mean, and status codes say how it finished.

Why it matters: Northline's stock update was sent with GET and a body. The server ignored the body, the quantity never changed, and the caller logged "success" because the connection opened. The method was the defect.

Before this lesson: Introduction to APIs and enterprise integration.

What you will be able to do

Prerequisites

Lesson 1. You do not need to run a server.

Methods, headers, and status codes

The method semantics below follow RFC 9110 (https://www.rfc-editor.org/rfc/rfc9110). They are properties of HTTP, not of one vendor.

MethodTypical use in this courseIdempotent?
GETRead a resource. No body is required.Yes. Repeating it does not change the resource.
POSTAsk the server to process a new operation, often a create.No. Repeating it can create a second record.
PUTReplace the resource at that URL with the body you send.Yes. Repeating the same body leaves the same result.
PATCHChange only the fields you send.Not guaranteed. Repeat it only if that API's contract says the patch is safe to repeat.
DELETERemove the resource at that URL.Yes. Deleting it again still leaves it gone.

Idempotent means one successful call and an identical repeat leave the resource in the same state. It does not mean "the server enjoys duplicates."

Headers used throughout this course:

Status codes you will use. The class is the first digit.

An error is a response whose status is not in the 2xx class, plus a body that a person can read. A timeout is not a status code. It means no response arrived.

Teacher walkthrough: update on-hand quantity

Figures are illustrative. SKU FX-100 has 80 units in the warehouse.

Validation: the warehouse screen shows the same on_hand as the GET body after the write.

A second workplace case

A monitoring probe uses POST to "check health" because the author wanted a body. Each probe inserts a row. The health check is now a write. The fitting method is GET, which RFC 9110 classifies as safe: it should not change the resource.

Failure example: 200 with an error in the body

Symptom: The client treats every response as success. The body says "status": "error", "message": "unknown sku". Stock is not updated. The log says the call worked.

Diagnosis: The HTTP status was 200, so the client's "did the socket work" check passed. The business failure was hidden in the body. The root cause is a contract that reports failure as success.

Correction: Failures use a non-2xx status. The body may explain the error. The client branches on the status code first. A field named status inside a 200 body is not a substitute.

Validation: Call with SKU NO-SUCH. The status is 404, and the client does not write a stock movement.

Guided practice: pick the method and the status

Scenario: Northline must record one supplier payment of 1,500. Repeating the click must not pay twice. Figures are illustrative.

Hints:

Complete solution:

Recording a payment is a new business event, so the first design is POST, and POST is not idempotent. The contract therefore requires an idempotency key that the server stores with the payment. The same key and the same body return the original result instead of a second payment. A supplier id that does not exist is 404, not 200. An authenticated caller who may not pay is 403, not 401. Validation: send the same key twice and count payments. The count stays 1.

Independent practice

Take one operation your team wants between two systems.

Acceptance criteria:

Common mistakes

  • Using GET with a body to perform a write.
  • Retrying POST because "the network blinked," and creating a second order.
  • Mapping every failure to 500, including bad input.
  • Reading 401 and 403 as the same event. 401 means the caller is not authenticated. 403 means they are authenticated and not allowed.

Quick check

  1. Which methods in the table are idempotent by HTTP's own rules?
  2. What is the difference between 401 and 403?
  3. A client receives 204. What should it parse?
  4. Why is a second identical PUT of the same item body safe?
  5. Why is Idempotency-Key not something you may assume on every API?

Answers:

  1. GET, PUT, and DELETE. PATCH is not guaranteed. POST is not.
  2. 401: not authenticated. 403: authenticated and not permitted.
  3. Nothing. 204 means success with no body.
  4. PUT replaces the resource with that body. The same body leaves the same resource.
  5. It is a convention some APIs document. HTTP does not require it.

Lesson summary

Choose the method for the kind of operation, read the status before the body, and do not retry a non-idempotent call unless the contract gives you a key that makes the repeat the same operation.

Bridge to the next lesson

The bodies in these examples are JSON. The next lesson is how objects, arrays, and nested fields are shaped, and how you reject a payload before it touches the ERP.