Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.
The Response object returned by a fetch() call contains all the information about the network request and response.
Metadata
headers
Accessing the headers property on the response object lets you inspect the HTTP headers in the response:
fetch('./file.json').then(response => {
console.log(response.headers.get('Content-Type'))
console.log(response.headers.get('Date'))
})

status
This property is an integer representing the HTTP response status.
- 101, 204, 205, and 304 indicate a null body
- 200 to 299, inclusive, indicate success
- 301, 302, 303, 307, and 308 indicate a redirect
fetch('./file.json').then(response => console.log(response.status))
statusText
statusText is a property representing the status message of the response. If the request is successful, statusText is OK.
fetch('./file.json').then(response => console.log(response.statusText))
url
url is the full URL of the resource that was fetched.
fetch('./file.json').then(response => console.log(response.url)) Lessons in this unit:
| 0: | Introduction |
| 1: | How to use Fetch |
| 2: | Catching errors in network requests |
| 3: | ▶︎ The Response object |
| 4: | Getting the body content |
| 5: | The Request object |
| 6: | Request headers |
| 7: | POST requests |