Skip to content

Join the Seedly owners community →

API Fundamentals

HTTP Methods

GET, POST, PUT, DELETE explained

Written by 12 min read1 activity
Sprout, your presenter

Sprout presents

GET, POST, PUT and DELETE. Four verbs do most of the work on the web, and each has a precise meaning. I adore precise meanings.GET, POST, PUT and DELETE. Four verbs do most of the work on the web, and each has a precise meaning. I adore precise meanings.

Sprout holds up four coloured paddles showing an eye, a plus, a looping arrow and a cross
Each HTTP method tells the API what you want to do

When you talk to an API, you've gotta tell it what you're trying to do. Grab some info? Save something new? Change something? Delete it? HTTP methods are how you say which one.

HTTP stands for Hypertext Transfer Protocol, and it's basically the language of the web. Any time you visit a website or use an app that connects to the internet, HTTP is working away in the background.

The Four Main Methods#

There are four HTTP methods you'll use WAY more than any others. Each one tells the API what kind of action you want.

GET: Read Data#

GET is the most common one. It means "give me some information." You're just looking around and nothing gets changed.

Examples of GET

  • Show me all the products
  • Show me user number 42
  • Show me today's weather
GET /products
GET /users/42
GET /weather?city=Seattle

Every time you visit a website, your browser sends a GET request. It's basically saying "give me this webpage."

POST: Create Data#

POST means "I'm sending you new data to save." You're creating something that didn't exist before.

Examples of POST

  • Create a new user account
  • Add a new product
  • Submit a new order
POST /users
{
  "name": "Sarah",
  "email": "[email protected]"
}

Filled out a form on a website and clicked "Submit"? That was probably a POST request, sending your new info off to get saved.

PUT: Update Data#

PUT means "replace this data with new data." You're changing something that already exists.

Examples of PUT

  • Update a user's email address
  • Change a product's price
  • Edit a blog post
PUT /users/42
{
  "name": "Sarah",
  "email": "[email protected]"
}

PUT replaces the WHOLE thing. If you update a user, you send all their information, even the parts that didn't change.

DELETE: Remove Data#

DELETE means "remove this." You're getting rid of something for good.

Examples of DELETE

  • Delete a user account
  • Remove a product from the store
  • Cancel an order
DELETE /users/42

DELETE requests are usually simple. You just point at the thing you want gone. Be careful though... deleted data is often gone for good, and there's no "oops" button.

A Real-World Example#

Say you're building a simple to-do list app. Here's how each method shows up.

Step 1. GET: View Your Tasks#

When you open the app, it sends a GET request to grab all your tasks.

GET /tasks

The server sends back your list of tasks.

Step 2. POST: Add a New Task#

You type a new task and click "Add," and the app sends a POST request.

POST /tasks
{
  "title": "Buy groceries",
  "completed": false
}

The server creates the task and saves it.

Step 3. PUT: Mark Task Complete#

You check off a task, and the app sends a PUT request to update it.

PUT /tasks/1
{
  "title": "Buy groceries",
  "completed": true
}

The server updates the task's status.

Step 4. DELETE: Remove a Task#

You delete a task, and the app sends a DELETE request.

DELETE /tasks/1

The server removes the task permanently.

CRUD Operations#

You'll hear developers say CRUD a lot. It sounds gross, but it's just short for this.

  • Create = POST
  • Read = GET
  • Update = PUT
  • Delete = DELETE

Almost every app needs these four basic operations. Users, products, messages, whatever it is, you've gotta create them, read them, update them and delete them.

How Requests Travel#

Sprout swaps a card on a cork board while another card drops into a wicker bin
Update a task with PUT, remove one with DELETE

Here's what happens when you make an API request.

  1. Your app builds a request with a method (GET, POST, etc.)
  2. The request travels over the internet to the server
  3. The server looks at the method to understand what you want
  4. The server does the work (reads, creates, updates, or deletes)
  5. The server sends a response back to your app

All of that happens in milliseconds. It feels instant, but there's a LOT going on behind the curtain.

Quick Reference#

MethodActionExampleChanges Data?
GETReadView a productNo
POSTCreateAdd new productYes
PUTUpdateChange product priceYes
DELETERemoveDelete a productYes

TL;DR#

  • HTTP methods tell the API what action you want
  • GET = read data (doesn't change anything)
  • POST = create new data
  • PUT = update existing data
  • DELETE = remove data
  • CRUD (Create, Read, Update, Delete) is the foundation of most apps

What's Next?#

Now you know the different ways to interact with an API. Next up are URLs and endpoints, the addresses where you actually send your requests...

This lesson ends with a short activity.