GET, PUT y DELETE ya son idempotentes por diseño HTTP. Para POST y PATCH en recursos sensibles (tareas, OS, tickets), sigue estas prácticas.
- Envía un identificador generado por tu sistema en
externalId(p. ej. ID del ERP). Antes de crear, consulta elGETcorrespondiente filtrando porexternalId. - Si existe, actualiza con
PATCH; si no, crea conPOST.
- Usa
deliveryIddel payload para deduplicar del lado cliente (write-once en una tablawebhook_deliveries).
async function postWithSafety(body) {
const existing = await findByExternalId(body.externalId);
if (existing) return existing;
try {
return await api.post('/tasks', body);
} catch (err) {
if (err.status === 409) {
return findByExternalId(body.externalId);
}
throw err;
}
}- Soporte nativo a
Idempotency-Key(estilo Stripe) — consulta el changelog.