API FUNDAMENTALS / LESSON 02
HTTP Methods.
GET, POST, PUT, DELETE explained

Loading the lesson…
Loading activities…
API FUNDAMENTALS / LESSON 02
GET, POST, PUT, DELETE explained

Loading the lesson…
Loading activities…
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.
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 is the most common one. It means "give me some information." You're just looking around and nothing gets changed.
Examples of GET
Every time you visit a website, your browser sends a GET request. It's basically saying "give me this webpage."
POST means "I'm sending you new data to save." You're creating something that didn't exist before.
Examples of POST
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 means "replace this data with new data." You're changing something that already exists.
Examples of PUT
PUT replaces the WHOLE thing. If you update a user, you send all their information, even the parts that didn't change.
DELETE means "remove this." You're getting rid of something for good.
Examples of DELETE
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.
Say you're building a simple to-do list app. Here's how each method shows up.
When you open the app, it sends a GET request to grab all your tasks.
The server sends back your list of tasks.
You type a new task and click "Add," and the app sends a POST request.
The server creates the task and saves it.
You check off a task, and the app sends a PUT request to update it.
The server updates the task's status.
You delete a task, and the app sends a DELETE request.
The server removes the task permanently.
You'll hear developers say CRUD a lot. It sounds gross, but it's just short for this.
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.
Here's what happens when you make an API request.
All of that happens in milliseconds. It feels instant, but there's a LOT going on behind the curtain.
| Method | Action | Example | Changes Data? |
|---|---|---|---|
| GET | Read | View a product | No |
| POST | Create | Add new product | Yes |
| PUT | Update | Change product price | Yes |
| DELETE | Remove | Delete a product | Yes |
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...