Fetch API: GET POST PUT DELETE
Make GET requests with fetch, send JSON bodies in POST and PUT requests, and call DELETE endpoints to remove resources.
The Fetch API
fetch() is the modern browser API for HTTP requests. It returns a Promise that resolves to a Response object. Standard in all modern browsers and Node.js 18+.
Basic GET Request
The simplest fetch — pass a URL, await the response, parse JSON.
async function fetchUsers() {
const res = await fetch('https://api.example.com/users');
if (!res.ok) throw new Error('HTTP ' + res.status);
const users = await res.json();
return users;
}All lessons in this course
- Fetch API: GET POST PUT DELETE
- Axios: Interceptors and Base URL
- Error Handling: HTTP Status Codes
- SWR and React Query for Data Caching