Lesson 1.1Free preview

Methods, status codes, and headers

GET reads and must not change anything.

5mBeginner21.3k students

Overview

The protocol already made these decisions

GET reads and must not change anything. PUT replaces and is idempotent. POST creates and is not. DELETE removes and should be safe to repeat. Following that is what lets caches, proxies, and retry logic behave correctly without knowing anything about your domain.

Status codes are part of your API contract. A 200 with an error message in the body defeats every client library, every monitor, and every retry policy in the path.

Idempotency matters most for retries. A client that times out will retry, and if your create endpoint is not idempotent you will produce duplicates — an idempotency key is the standard remedy.

In this lesson you will:

  • Use the method that matches the operation
  • Return a status code that means something
  • Understand idempotency and safety

Resources

Next Lesson
Methods, status codes, and headers — API Design with Node.js — Vertex