POST Requests in JavaScript
From the Fetch API cheat sheet · Basic Requests · verified Jul 2026
POST Requests
Sending data to create new resources
javascript
// POST JSON data
const response = await fetch('https://api.example.com/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'John Doe',
email: 'john@example.com'
})
})
// POST FormData (multipart/form-data)
const formData = new FormData()
formData.append('name', 'John Doe')
formData.append('avatar', fileInput.files[0])
const response = await fetch('https://api.example.com/users', {
method: 'POST',
body: formData // No Content-Type header needed!
})
// POST URL encoded form
const params = new URLSearchParams()
params.append('username', 'john')
params.append('password', 'secret')
const response = await fetch('https://api.example.com/login', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: params
})🟢 Always set Content-Type for JSON, omit for FormData
⚡ FormData automatically sets multipart boundary
⚠️ Fetch doesn't support upload progress - use XMLHttpRequest
💡 Include request IDs for debugging and tracing