🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
HTML MASTER CLASS /// LEARN TAGS /// BUILD STRUCTURE /// SEMANTIC WEB /// HTML MASTER CLASS /// LEARN TAGS ///

HTTP Methods (CRUD)

Master the core HTTP methods used in REST APIs: GET, POST, PUT, PATCH, and DELETE. Understand how they map to database CRUD operations and the critical concept of Idempotency.

Narrated Video Summary
data-composition-id="apicreationmanipulation-module1_lesson3"1280×720 @ 30fps5 clips2:26 total

The Verbs of REST

We established that REST URLs should be strictly nouns (e.g., `/users`). So how does the server know what action to perform on that noun? This is the job of HTTP Methods (often called HTTP Verbs). By attaching a specific verb to the request, you explicitly tell the server whether you want to Read, Create, Update, or Delete the resource. This maps perfectly to the database concept of CRUD.

// 🌐 HTTP Methods map to CRUD

// Create -> POST
// Read   -> GET
// Update -> PUT / PATCH
// Delete -> DELETE

GET: Reading Data

The GET method is used exclusively to request data from a specified resource. It is the most common HTTP method on the internet. Every time you type a URL into your browser and hit Enter, your browser performs a GET request under the hood. Crucially, GET requests are considered 'Safe' and 'Idempotent'. This means performing a GET request should NEVER alter or mutate data in the database.

// 📥 GET Request
// Action: Fetch data. Do NOT modify anything.

GET /api/products
GET /api/products/42

POST: Creating Data

The POST method is used to send data to the server to create a new resource. Unlike GET, POST requests carry a 'Body' (usually a JSON payload containing the new data). POST requests are NOT idempotent. This means if you execute the exact same POST request 10 times, the server will create 10 distinct, duplicate records in the database. When you submit a signup form, it sends a POST request.

// 📤 POST Request
// Action: Create a new resource.

POST /api/users
Content-Type: application/json

{
  "name": "Alice",
  "email": "alice@example.com"
}

PUT vs PATCH: Updating Data

When you need to modify existing data, you use PUT or PATCH. While often used interchangeably by junior developers, they have a strict semantic difference. PUT is a complete replacement; it overwrites the entire resource. If you omit a field in a PUT request, that field is deleted. PATCH is a partial update; it only modifies the specific fields you send, leaving the rest of the object untouched.

// Existing User: { id: 1, name: "A", age: 20 }

// 🔄 PUT Request (Full Replace):
PUT /users/1 { name: "B" }
// Result: { id: 1, name: "B" } -> age is lost!

// 🩹 PATCH Request (Partial Update):
PATCH /users/1 { name: "B" }
// Result: { id: 1, name: "B", age: 20 } -> age kept!

DELETE: Removing Data

The DELETE method is straightforward: it removes a specified resource from the server. Like GET, a DELETE request typically does not contain a body payload. The ID of the resource to be deleted is usually passed directly in the URL (e.g., `/users/42`). You have now mastered the grammar of the web. In the next module, we will explore the tools used to actually execute these requests.

/* Verbs Complete */
.verbs { next: 'api_tools'; }
0:00 / 2:26
Scene 1 / 5 — The Verbs of REST
Total XP: 0|💻 apicreationmanipulation XP: 0

Skill Matrix

UNLOCK NODES BY LEARNING NEW TAGS.

HTTP Verbs

Actions of the web.

Quick Quiz //

Which acronym perfectly maps the four primary database operations to the four primary HTTP methods?


🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.

If URLs are the nouns of the web, HTTP Methods are the verbs. They provide the exact action to perform on the targeted resource.

1The Verbs of REST

We established that REST URLs should be strictly nouns (e.g., /users). So how does the server know what action to perform on that noun? This is the job of HTTP Methods (often called HTTP Verbs). By attaching a specific verb to the request, you explicitly tell the server whether you want to Read, Create, Update, or Delete the resource. This maps perfectly to the database concept of CRUD.

+
// HTTP Methods map to CRUD

POST -> Create
GET -> Read
PUT -> Update
DELETE -> Delete
localhost:3000
localhost:3000
CRUD mapped: Verbs mapped securely to their corresponding database actions.

2GET: Reading Data

The GET method is used exclusively to request data from a specified resource. It is the most common HTTP method on the internet. Every time you type a URL into your browser and hit Enter, your browser performs a GET request under the hood. Crucially, GET requests are considered 'Safe' and 'Idempotent'. This means performing a GET request should NEVER alter or mutate data in the database. Browsers rely on this safety to cache GET responses aggressively.

+
// Fetching data without side effects:

GET /api/products
GET /api/products/42
localhost:3000
localhost:3000
Data retrieved: Safe, cacheable read operation completed without mutating the database.

3POST: Creating Data

The POST method is used to send data to the server to create a new resource. Unlike GET, POST requests carry a 'Body' (usually a JSON payload containing the new data). POST requests are NOT idempotent. This means if you execute the exact same POST request 10 times, the server will create 10 distinct, duplicate records in the database. When you submit a signup form, it sends a POST request. The browser knows this isn't safe to repeat blindly.

+
POST /api/users
Content-Type: application/json

{
  "name": "Alice"
}
localhost:3000
localhost:3000
Resource created: Non-idempotent operation safely processed the payload.

4PUT vs PATCH: Updating Data

When you need to modify existing data, you use PUT or PATCH. While often used interchangeably by junior developers, they have a strict semantic difference. PUT is a complete replacement; it overwrites the entire resource. If you omit a field in a PUT request, that field is deleted. PATCH is a partial update; it only modifies the specific fields you send, leaving the rest of the object untouched. Modern architectures lean heavily on PATCH for safety.

+
// Existing: { id: 1, name: "A", age: 20 }

PUT /users/1 { name: "B" }
// Result: { id: 1, name: "B" } (age lost!)

PATCH /users/1 { name: "B" }
// Result: { id: 1, name: "B", age: 20 }
localhost:3000
localhost:3000
Update applied: Use PATCH to safely mutate partial structures without data loss.

5DELETE: Removing Data

The DELETE method is straightforward: it removes a specified resource from the server. Like GET, a DELETE request typically does not contain a body payload. The ID of the resource to be deleted is usually passed directly in the URL (e.g., /users/42). It is also idempotent; deleting a resource once removes it, and firing that same delete request again just results in a 404 (because it's already gone), leaving the server in the exact same state.

+
// Securely wipe the record:

DELETE /users/42
localhost:3000
localhost:3000
Resource destroyed: Entity purged idempotently from the backend cluster.

6Step-by-Step Breakdown

The Verbs of REST. We established that REST URLs should be strictly nouns (e.g., /users). So how does the server know what action to perform on that noun? This is the job of HTTP Methods (often called HTTP Verbs). By attaching a specific verb to the request, you explicitly tell the server whether you want to Read, Create, Update, or Delete the resource. This maps perfectly to the database concept of CRUD.

GET: Reading Data. The GET method is used exclusively to request data from a specified resource. It is the most common HTTP method on the internet. Every time you type a URL into your browser and hit Enter, your browser performs a GET request under the hood. Crucially, GET requests are considered 'Safe' and 'Idempotent'. This means performing a GET request should NEVER alter or mutate data in the database.

Which of the following is a strict architectural rule regarding the GET method in a REST API?

  • GET requests must include a large JSON body payload.
  • GET requests must be 'safe'; they should never alter, mutate, or delete data in the database.

POST: Creating Data. The POST method is used to send data to the server to create a new resource. Unlike GET, POST requests carry a 'Body' (usually a JSON payload containing the new data). POST requests are NOT idempotent. This means if you execute the exact same POST request 10 times, the server will create 10 distinct, duplicate records in the database. When you submit a signup form, it sends a POST request.

PUT vs PATCH: Updating Data. When you need to modify existing data, you use PUT or PATCH. While often used interchangeably by junior developers, they have a strict semantic difference. PUT is a complete replacement; it overwrites the entire resource. If you omit a field in a PUT request, that field is deleted. PATCH is a partial update; it only modifies the specific fields you send, leaving the rest of the object untouched.

You have a user object with 20 different fields (name, email, address, etc.). The user only wants to update their email address. Which HTTP method is the most semantically correct to use?

  • PUT
  • PATCH

DELETE: Removing Data. The DELETE method is straightforward: it removes a specified resource from the server. Like GET, a DELETE request typically does not contain a body payload. The ID of the resource to be deleted is usually passed directly in the URL (e.g., /users/42). You have now mastered the grammar of the web. In the next module, we will explore the tools used to actually execute these requests.

Level Up 🚀

Advanced cheat sheets, SEO tricks, and interview prep for this topic.

Browser Support

ChromeSupported

Fully supported.

FirefoxSupported

Fully supported.

SafariSupported

Fully supported.

EdgeSupported

Fully supported.

Accessibility (A11y)

1Semantic Usage

Using the proper structure for The Verbs of REST ensures that screen readers can correctly interpret the content hierarchy and purpose.

<!-- Apply semantic elements appropriately -->

SEO Implications

  • 1

    Contextual Relevance

    Proper implementation of The Verbs of REST provides search engine crawlers with better context, improving the indexing accuracy of your page.

Best Practices

Clean Code

Always validate your structure when using The Verbs of REST to prevent layout shifts and DOM inconsistencies.

Separation of Concerns

Keep styling and behavior separate from the structural markup of The Verbs of REST.

Frequent Bugs

THE BUG

Unexpected layout shifts or styling failures.

THE FIX

Ensure all implementations related to The Verbs of REST are properly structured according to strict specifications.

Real-World Examples

Production Usage

Here is how The Verbs of REST is typically implemented in a professional, robust application.

<!-- Best practice implementation of The Verbs of REST -->
<div class="production-ready">
  <!-- Content -->
</div>

Interview Prep

?Frequently Asked Questions

Pascual Vila

Pascual Vila

Frontend Instructor // Code Syllabus

Common Pitfalls & Errors

The Error //

Not reading error messages carefully

Uncaught TypeError: Cannot read properties of undefined (reading 'length') // Solution: Ensure the variable you are calling .length on is initialized as a string or an array, not undefined.

The Solution //

Most of the time, the compiler or interpreter tells you exactly what line caused the crash and why. Read stack traces from the top down to identify the root cause.

The Error //

Hardcoding sensitive credentials

// Wrong const API_KEY = 'sk-123456789'; // Correct const API_KEY = process.env.API_KEY;

The Solution //

Never hardcode API keys, passwords, or secrets in your source code. Use environment variables (.env files) to keep them secure and out of version control.

Lesson Glossary

[01]CRUD

Create, Read, Update, Delete. The four basic functions of persistent storage, which map directly to POST, GET, PUT/PATCH, and DELETE.

Code Preview
The Database Actions

[02]Idempotent

An operation that can be applied multiple times without changing the result beyond the initial application (e.g., PUT, DELETE).

Code Preview
The Safe Repeat

[03]Payload / Body

The data sent by the client to the server in an HTTP request, typically formatted as JSON, used heavily in POST and PUT/PATCH requests.

Code Preview
The Cargo

[04]GET

The HTTP method used exclusively to read or retrieve data without causing any side effects on the server.

Code Preview
The Reader

[05]PATCH

The HTTP method used for applying partial modifications to a resource, contrasting with PUT's full replacement.

Code Preview
The Surgeon

Continue Learning