GET, PUT e DELETE já são idempotentes por padrão HTTP. Para POST e PATCH em recursos sensíveis (tarefas, OS, tickets), siga as práticas abaixo.
- Envie um identificador gerado pelo seu sistema em
externalId(ex.: ID do ERP). Antes de criar, chame oGETcorrespondente filtrando porexternalId. - Se existir, atualize via
PATCH; se não, crie viaPOST.
- Use
deliveryIddo payload para deduplicar do seu lado (write-once em tabelawebhook_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;
}
}- Suporte nativo a
Idempotency-Key(padrão Stripe-like) — acompanhe o changelog.