IK
Interview Knowledge Book
Темы
Практика
Примеры
Песочница
EN
node
HTTP idempotency и pagination shape
Верните same result for repeated idempotency key и expose cursor-style next page token.
index.js
const idempotencyStore = new Map(); function charge(key) { if (!idempotencyStore.has(key)) idempotencyStore.set(key, { id: 'ch_1' }); return idempotencyStore.get(key); } function listPage(after) { return { items: ['a', 'b'], nextCursor: after ? null : 'p2' }; } console.log('first charge', charge('request-1').id); console.log('repeat charge', charge('request-1').id); console.log('next cursor', listPage().nextCursor);
Запустить
Остановить
Сбросить