cURL
curl --request DELETE \ --url https://api.example.com/api/image/:id
Authorization: Bearer <your-token>
HTTP/1.1 204 No Content
{ "error": "Unauthorized" }
curl -X DELETE https://api.example.com/api/image/42 \ -H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9..."
fetch('https://api.example.com/api/image/42', { method: 'DELETE', headers: { 'Authorization': `Bearer ${token}` } }) .then(response => { if (response.status === 204) { console.log('Image deleted successfully'); } });
import requests headers = { 'Authorization': f'Bearer {token}' } response = requests.delete( 'https://api.example.com/api/image/42', headers=headers ) if response.status_code == 204: print('Image deleted successfully')
import axios from 'axios'; try { await axios.delete('https://api.example.com/api/image/42', { headers: { 'Authorization': `Bearer ${token}` } }); console.log('Image deleted successfully'); } catch (error) { console.error('Failed to delete image:', error); }
images/
fs.unlinkSync()
app.delete('/api/image/:id', checkJwt, async (req, res) => { const id = Number(req.params.id); const fileInfo = await getImage(id); // delete file fs.unlinkSync(path.join(imagesDir, fileInfo.name)); // delete from db await deleteImage(id); res.status(204).end(); });
export async function deleteImage(id: number): Promise<void> { await db('images').where({ id }).del(); }