Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Chunk unbounded id lists instead of cramming them into one query string
Split large id batches into bounded requests (or POST a body) to avoid 414 URI Too Long.
Bad example
| 1 | // Hundreds of ids -> URL can exceed ~8KB -> 414 |
| 2 | const url = `${base}/api/lookup?ids=${ids.join(',')}`; |
| 3 | const res = await fetch(url); |
Explanation (EN)
A large batch produces a very long URL that many proxies and servers reject with 414, causing the lookup to fail and downstream data to silently go missing.
Objašnjenje (HR)
Velika serija proizvodi vrlo dug URL koji mnogi proxyji i serveri odbijaju s 414, zbog čega dohvat ne uspije i podaci nizvodno tiho nedostaju.
Good example
| 1 | const CHUNK = 50; |
| 2 | const merged = new Map<number, Item>(); |
| 3 | for (let i = 0; i < ids.length; i += CHUNK) { |
| 4 | const slice = ids.slice(i, i + CHUNK); |
| 5 | const res = await fetch(`${base}/api/lookup?ids=${slice.join(',')}`); |
| 6 | const data = await res.json(); |
| 7 | for (const item of data.items) merged.set(item.id, item); |
| 8 | } |
Explanation (EN)
Chunking keeps every URL within limits and merges the partial results, so large batches succeed.
Objašnjenje (HR)
Dijeljenje u dijelove drži svaki URL unutar granica i spaja djelomične rezultate, pa velike serije uspijevaju.