You can send five types of requests. Each type is represented by a keyword. These keywords are also called HTTP Methods or HTTP Verbs.
The five keywords are:
GETPOSTPUTPATCHDELETE
Here’s what they do:
| Method | Usage |
|---|---|
GET |
Get (or read) a resource |
POST |
Create (or save) a new resource |
PUT |
Update a specific part of the resource |
PATCH |
Update the entire resource |
DELETE |
Delete the resource |
Browsers perform a GET request when you visit a link.
Methods vs CRUD
You may have heard of CRUD when you look for information about Async JS and Rest APIs.
CRUD is just an acronym of four words:
- Create
- Read
- Update
- Delete
It is used to signal the kind of operations you can make between a server and a database.
| Verb | Usage |
|---|---|
| Create | Add to database |
| Read | Get from database |
| Update | Update in database |
| Delete | Delete from database |
HTTP Methods are used to trigger CRUD operations. The following table shows you their relationship.
| Method | CRUD |
|---|---|
GET |
Read |
POST |
Create |
PUT |
Update |
PATCH |
Update |
DELETE |
Delete |
Setting a method
You can set a method by adding it to the request’s options.
fetch('https://link-to-resource', { method: 'post',})If you use zlFetch, you have two choices:
- You can add the method to the request’s options
- Or use the method directly.
// These two are equivalentzlFetch('https://link-to-resource', { method: 'post',})
zlFetch.post('https://link-to-resource')That’s all you need to know about request methods!
Welcome! Unfortunately, you don’t have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson