Course contentsShow
← JavaScript
Lesson 2268 of 2,72347. Networking PrimitivesFree lesson

Request Methods and HTTP Verbs

Understand GET, POST, PUT, PATCH, DELETE and how to specify the method property when constructing a Request.

Request Methods and HTTP Verbs

You'll learn how to specify the HTTP method when constructing a Request object to control what action your network request performs.

What Are HTTP Methods?

Think of HTTP methods (also called "verbs") as different instructions you give to a server. Just like you might ask someone for information, give them a document, update a record, or delete a file, HTTP methods tell the server what operation you want to perform.

The most common methods are:

  • GET – Retrieve data (like reading a book from a shelf)
  • POST – Create new data (like adding a new book to the library)
  • PUT – Replace existing data completely (like rewriting an entire book)
  • PATCH – Update part of existing data (like editing a chapter)
  • DELETE – Remove data (like removing a book from the library)

Specifying the Method Property

When constructing a Request, you specify the HTTP method using the method property in the options object:

const request = new Request('https://api.example.com/users', {
  method: 'POST'
});

If you don't specify a method, it defaults to GET. Here are examples of different verbs:

// Retrieve data
const getRequest = new Request('/api/data', { method: 'GET' });

// Create new resource
const postRequest = new Request('/api/users', { method: 'POST' });

// Replace entire resource
const putRequest = new Request('/api/users/123', { method: 'PUT' });

// Update part of resource
const patchRequest = new Request('/api/users/123', { method: 'PATCH' });

// Remove resource
const deleteRequest = new Request('/api/users/123', { method: 'DELETE' });

The method property is case-insensitive but conventionally written in uppercase.

Key Takeaway: Use the method property in your Request options to specify which HTTP verb your request should use—GET for retrieving, POST for creating, PUT/PATCH for updating, and DELETE for removing data.