Skip to content

Traffic Types - HTTP Methods

So far we’ve mostly looked at GET requests (sightseeing). But traffic on the Data Superhighway comes in many flavors. Express segregates traffic not just by where it’s going (path), but by what it wants to do (method).

Futuristic highway sorting station with lanes for GET (blue cars), POST (green trucks), PUT (yellow construction vehicles), and DELETE (red demolition dozers).

Fig 1: Traffic Sorting Logic.

Here is the standard CRUD breakdown for our interchange:

MethodActionDriving Analogy
GETReadSightseeing. Just looking.
POSTCreateDelivery Truck. Dropping off new cargo.
PUTUpdate (Replace)Road Construction. Replacing the whole lane.
PATCHUpdate (Partial)Pothole repair. Fixing just one part.
DELETEDeleteDemolition Crew. Removing the road entirely.

Express is strict. app.get('/things') and app.post('/things') are two completely different roads, even if they share the same asphalt (URL).

// GET /things -> "Show me the things"
app.get('/things', (req, res) => {
res.send('Here is the list.');
});
// POST /things -> "Take this new thing"
app.post('/things', (req, res) => {
res.send('New thing received.');
});
// DELETE /things -> "Destroy the things"
app.delete('/things', (req, res) => {
res.send('Things destroyed.');
});

Here is a pothole you will hit immediately: Native HTML Forms only support GET and POST.

If you try to set <form method="DELETE">, the browser will ignore you and send a GET request instead (because it defaults to GET if it doesn’t understand the method).

  1. AJAX / Fetch: JavaScript (on the client) has no such limitation. fetch('/things', { method: 'DELETE' }) works perfectly.
  2. Method Override: A middleware technique (often used in classic SSR apps) where we trick the server. We send a POST request but add a query string like ?_method=DELETE. The server sees the note and “pretends” it received a DELETE.

For now, just know that if you are building a pure HTML/Simple Express app without client-side JS, you are mostly stuck in the GET and POST lanes.


Express HTTP Method Routing - Demo Repo

MDN HTTP Methods

⏭ Dead Ends

What happens when a driver takes a wrong turn and ends up off the map?