Course contentsShow
← Web Development
Lesson 847 of 2,98215. Browser NetworkingFree lesson

Request Methods and URL

Working with request.method, request.url, and request.destination properties.

Request Methods and URL

What You'll Learn

You'll learn how to inspect and use the request.method, request.url, and request.destination properties to understand and control the details of HTTP requests you've created.

Understanding Request Properties

When you create a Request object with the Fetch API, it comes with several built-in properties that describe what kind of request it is and where it's going. Think of these properties like the address label and delivery instructions on a package—they tell the browser exactly what to do with your request.

request.method

The method property tells you which HTTP verb the request uses (GET, POST, PUT, DELETE, etc.). This is a read-only property that reflects what you specified when creating the request:

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

console.log(req.method); // "POST"

request.url

The url property contains the full URL where the request is headed. This is also read-only and returns the complete, absolute URL as a string:

const req = new Request('/api/users');
console.log(req.url); // Full URL: "https://yourdomain.com/api/users"

request.destination

The destination property indicates the type of content being requested—like "document", "image", "script", "style", or an empty string for fetch requests. This helps browsers prioritize and handle different resource types appropriately:

const req = new Request('https://example.com/data.json');
console.log(req.destination); // "" (empty for fetch)

These properties are particularly useful when you need to inspect or log requests, or when building middleware that makes decisions based on request characteristics.

Key Takeaway: The request.method, request.url, and request.destination properties let you inspect the fundamental characteristics of any Request object—what action it performs, where it's going, and what type of resource it expects.