Introduction
When you use the internet, your device often needs to ask a website for information or send information to it. Knowing how these requests work helps you understand how websites and apps communicate behind the scenes.
Jump into concepts and practice - no test required
Imagine you are at a library. When you ask the librarian for a book, you are making a GET request to get information. When you fill out a form to donate a book, you are making a POST request to send information that changes the library's collection.
┌─────────────┐ GET Request ┌─────────────┐
│ Your │─────────────────────────▶│ Website │
│ Device │ │ Server │
└─────────────┘ └─────────────┘
▲ │
│ │
│ Response with Data │
└───────────────────────────────────────┘
┌─────────────┐ POST Request ┌─────────────┐
│ Your │─────────────────────────▶│ Website │
│ Device │ │ Server │
└─────────────┘ └─────────────┘
▲ │
│ │
│ Response Confirming Receipt │
└───────────────────────────────────────┘GET request in web communication?fetch('https://api.example.com/data', {
method: 'GET',
body: JSON.stringify({name: 'Alice'})
})
What is the main problem with this code?