Stop 01 · Internet & Backend BasicsTopics · 6/15

HTTP Methods

Part of the Backend Developer Roadmap

In short

GET, POST, PUT, PATCH, DELETE. Five verbs cover almost every API you'll build. Pick the right one and other developers understand your API before reading any docs.

GET, POST, PUT, PATCH and DELETE — the verbs that tell a server what kind of operation a request represents, and the basis of RESTful API design.

The mascot pins a new notice on a canteen board while taking down an old one.

Think of it like this

The canteen notice board

Reading the board is GET. Pinning up a new notice is POST. Swapping a notice for a fresh full copy is PUT. Fixing just the date on it is PATCH. Taking it down is DELETE. Same board, five different actions.

Watch it happen

One notice, five methods

Client
API

POST /notices

1/6Create a new notice. The client doesn't choose the id, the server does.

The big ideas

What you need to know

GET only reads

GET must not change data. Browsers, caches and link previews send GET requests freely, assuming they're harmless.

POST creates

POST adds something new or triggers an action. Sending it twice usually creates two things.

PUT replaces, PATCH edits

PUT sends the full new version of a resource. PATCH sends only the fields that changed.

DELETE removes

DELETE /notices/9 removes that notice. Repeating it leaves the same result: still gone.

See it in code

Walk through the code

js
1const notices = new Map();2let nextId = 1;3app.get("/notices/:id", (req, res) => {4  const n = notices.get(Number(req.params.id));5  n ? res.json(n) : res.sendStatus(404);6});7app.post("/notices", (req, res) => {8  const n = { ...req.body, id: nextId++ };9  notices.set(n.id, n);10  res.status(201).json(n);11});12app.patch("/notices/:id", (req, res) => {13  const n = notices.get(Number(req.params.id));14  if (!n) return res.sendStatus(404);15  res.json(Object.assign(n, req.body, { id: n.id }));16});

1/3GET looks the notice up and returns it, or 404 if it doesn't exist.

Assumes const app = express() and app.use(express.json()). A PUT route would swap the whole object, and app.delete would call notices.delete(id) and reply 204.

Save yourself the pain

Common mistakes

Oops

Using GET /deleteUser?id=5 to delete things.

Do this instead

Crawlers and link previews fire GET requests on their own. Use DELETE /users/5 so nothing is removed by accident.

Oops

Sending a PUT with only the changed field and wiping out the rest.

Do this instead

PUT means 'here is the complete new version'. For a partial update, use PATCH.

Your mission

Finish the notice board API

~30 min

Quick check

A mobile app wants to change only a user's profile photo URL. Which request fits best?

Go deeper

  1. 1Build a tiny API with one endpoint per method against the same resource.
  2. 2Learn which methods are idempotent (safe to retry) and which aren't.
  3. 3Understand when to use PUT (full replace) vs PATCH (partial update).

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge